Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 668223f

Browse files
committedFeb 5, 2022
add 2161
1 parent 09a30b5 commit 668223f

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2161|[Partition Array According to Given Pivot](https://leetcode.com/problems/partition-array-according-to-given-pivot/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2161.java) ||Medium||
1112
|2160|[Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2160.java) ||Easy||
1213
|2156|[Find Substring With Given Hash Value](https://leetcode.com/problems/find-substring-with-given-hash-value/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2156.java) ||Medium||
1314
|2155|[All Divisions With the Highest Score of a Binary Array](https://leetcode.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2155.java) ||Medium||
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _2161 {
7+
public static class Solution1 {
8+
public int[] pivotArray(int[] nums, int pivot) {
9+
List<Integer> less = new ArrayList<>();
10+
List<Integer> greater = new ArrayList<>();
11+
int count = 0;
12+
for (int i = 0; i < nums.length; i++) {
13+
if (nums[i] < pivot) {
14+
less.add(nums[i]);
15+
} else if (nums[i] > pivot) {
16+
greater.add(nums[i]);
17+
} else {
18+
count++;
19+
}
20+
}
21+
for (int i = 0; i < nums.length; ) {
22+
int j = 0;
23+
while (j < less.size()) {
24+
nums[i++] = less.get(j++);
25+
}
26+
j = 0;
27+
while (j < count) {
28+
nums[i++] = pivot;
29+
j++;
30+
}
31+
j = 0;
32+
while (j < greater.size()) {
33+
nums[i++] = greater.get(j++);
34+
}
35+
}
36+
return nums;
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)
Failed to load comments.