Skip to content

Commit 62d53a4

Browse files
committed
add sol
1 parent 2556d71 commit 62d53a4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

leetcode/daily/2161/sol.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// https://leetcode.com/problems/partition-array-according-to-given-pivot/description/
2+
3+
package main
4+
5+
import "fmt"
6+
7+
func pivotArray(nums []int, pivot int) []int {
8+
left := []int{}
9+
equal := []int{}
10+
right := []int{}
11+
12+
for _, num := range nums {
13+
if num < pivot {
14+
left = append(left, num)
15+
} else if num == pivot {
16+
equal = append(equal, num)
17+
} else {
18+
right = append(right, num)
19+
}
20+
}
21+
22+
return append(left, append(equal, right...)...)
23+
}
24+
25+
func main() {
26+
nums := []int{9, 12, 5, 10, 14, 3, 10}
27+
pivot := 10
28+
29+
fmt.Print(pivotArray(nums, pivot))
30+
}

0 commit comments

Comments
 (0)