-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add solution and test-cases for problem 2161
- Loading branch information
Showing
3 changed files
with
52 additions
and
26 deletions.
There are no files selected for viewing
37 changes: 23 additions & 14 deletions
37
leetcode/2101-2200/2161.Partition-Array-According-to-Given-Pivot/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 19 additions & 2 deletions
21
leetcode/2101-2200/2161.Partition-Array-According-to-Given-Pivot/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(nums []int, pivot int) []int { | ||
i, j := 0, len(nums)-1 | ||
res := make([]int, len(nums)) | ||
for k := 0; k < len(nums); k++ { | ||
if nums[k] < pivot { | ||
res[i] = nums[k] | ||
i++ | ||
} | ||
} | ||
for k := len(nums) - 1; k >= 0; k-- { | ||
if nums[k] > pivot { | ||
res[j] = nums[k] | ||
j-- | ||
} | ||
} | ||
for ; i <= j; i++ { | ||
res[i] = pivot | ||
} | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters