1
/**
2
* @param {number[]} nums
3
* @param {number} pivot
4
* @return {number[]}
5
*/
6
var pivotArray = function (nums, pivot) {
7
let n = nums.length;
8

9
//first Solution with 3 separet Array
10
let lessPivot = [];
11
let equalPivot = [];
12
let bigerPivot = [];
13

14
for (let i = 0; i < n; i++) {
15
if (nums[i] < pivot) lessPivot.push(nums[i]);
16
else if (nums[i] === pivot) equalPivot.push(nums[i]);
17
else bigerPivot.push(nums[i]);
18
}
19
return lessPivot.concat(equalPivot.concat(bigerPivot));
20

21
//second Solution with one Array
22

23
let result = [];
24
for (let num of nums) {
25
if (num < pivot) result.push(num);
26
}
27

28
for (let num of nums) {
29
if (num === pivot) result.push(num);
30
}
31
for (let num of nums) {
32
if (num > pivot) result.push(num);
33
}
34
return result;
35
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0