MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / pivotArray

Method pivotArray

PartitionArrayAccordingToGivenPivot.java:2–32  ·  view source on GitHub ↗
(int[] nums, int pivot)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int[] pivotArray(int[] nums, int pivot) {
3 int lCount=0;
4 int gCount=0;
5 int pCount=0;
6 for(int num : nums){
7 if(num < pivot){
8 lCount++;
9 }else if(num > pivot){
10 gCount++;
11 }else{
12 pCount++;
13 }
14 }
15 int i=0;
16 int j=lCount;
17 int k=lCount + pCount;
18 int res[] = new int[nums.length];
19 for(int num : nums){
20 if(num < pivot){
21 res[i] = num;
22 i++;
23 }else if(num > pivot){
24 res[k] = num;
25 k++;
26 }else{
27 res[j] = num;
28 j++;
29 }
30 }
31 return res;
32 }
33}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected