Skip to content

Commit

Permalink
Q2161 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Mar 1, 2023
1 parent 7c06a89 commit ec009d4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions M_2161_PartitionArrayAccordingtoGivenPivot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public int[] pivotArray(int[] nums, int pivot) {
int[] ret= new int[nums.length];
int left=0; int right=nums.length-1;
int num_pivot=0;
for(int i=0;i<nums.length;i++){
if(nums[i]<=pivot){
if(nums[i]==pivot)
num_pivot++;
else
ret[left++]=nums[i];
}
if(nums[nums.length-1-i]>pivot){
ret[right--]=nums[nums.length-1-i];
}
}
for(int i=left; i<left+num_pivot;i++){
ret[i]=pivot;
}
return ret;
}
}

0 comments on commit ec009d4

Please sign in to comment.