We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 01e68fb commit f3c05abCopy full SHA for f3c05ab
contest/src/main/java/com/github/contest/array/ArrayLeetcode.kt
@@ -95,4 +95,25 @@ private fun IntArray.swap(from: Int, to: Int) {
95
this[to] = temp
96
}
97
98
+/**
99
+ * 2161. Partition Array According to Given Pivot
100
+ */
101
+fun pivotArray(nums: IntArray, pivot: Int): IntArray {
102
+ if (nums.hasSingle()) return nums
103
+ val res = mutableListOf<Int>()
104
+ for (i in 0 until nums.size) {
105
+ if (nums[i] < pivot) res.add(nums[i])
106
+ }
107
108
+ if (nums[i] == pivot) res.add(nums[i])
109
110
111
+ if (nums[i] > pivot) res.add(nums[i])
112
113
+
114
+ return res.toIntArray()
115
+}
116
117
118
119
0 commit comments