Skip to content

Commit a208695

Browse files
committed
Runtime: 12 ms (Top 37.13%) | Memory: 169.4 MB (Top 17.70%)
1 parent 6a187c0 commit a208695

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// Runtime: 12 ms (Top 37.13%) | Memory: 169.4 MB (Top 17.70%)
12
// Time complexity = 2n = O(n)
23
// Space complexity = O(1), or O(n) if the result array is including in the complexity analysis.
34

45
class Solution {
56
public int[] pivotArray(int[] nums, int pivot) {
67
int[] result = new int[nums.length];
78
int left = 0, right = nums.length - 1;
8-
9+
910
for(int i = 0; i < nums.length; i++) {
1011
if(nums[i] < pivot) {
1112
result[left++] = nums[i];
@@ -14,12 +15,12 @@ public int[] pivotArray(int[] nums, int pivot) {
1415
result[right--] = nums[nums.length - 1 - i];
1516
}
1617
}
17-
18+
1819
while(left <= right) {
1920
result[left++] = pivot;
2021
result[right--] = pivot;
2122
}
22-
23+
2324
return result;
24-
}
25-
}
25+
}
26+
}

0 commit comments

Comments
 (0)