Skip to content

Commit

Permalink
Create Partition Array According to Given Pivot.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokesh598 authored May 24, 2024
1 parent 2a1606b commit d27dd4a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Array/Partition Array According to Given Pivot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public int[] pivotArray(int[] nums, int pivot) {
int[] res = new int[nums.length];

int pointer = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] < pivot) {
res[pointer++] = nums[i];
}
}
for (int i = 0; i < nums.length; i++) {
if (nums[i] == pivot) {
res[pointer++] = nums[i];
}
}
for (int i = 0; i < nums.length; i++) {
if (nums[i] > pivot) {
res[pointer++] = nums[i];
}
}

return res;
}
}

0 comments on commit d27dd4a

Please sign in to comment.