You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/com/fishercoder/solutions/_360.java
+4-25
Original file line number
Diff line number
Diff line change
@@ -2,27 +2,6 @@
2
2
3
3
importjava.util.Arrays;
4
4
5
-
/**
6
-
* 360. Sort Transformed Array
7
-
*
8
-
* Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f(x) = ax2 + bx + c to each element x in the array.
9
-
10
-
The returned array must be in sorted order.
11
-
12
-
Expected time complexity: O(n)
13
-
14
-
Example:
15
-
nums = [-4, -2, 2, 4], a = 1, b = 3, c = 5,
16
-
17
-
Result: [3, 9, 15, 33]
18
-
19
-
nums = [-4, -2, 2, 4], a = -1, b = 3, c = 5
20
-
21
-
Result: [-23, -5, 1, 7]
22
-
23
-
Credits:
24
-
Special thanks to @elmirap for adding this problem and creating all test cases.
25
-
*/
26
5
publicclass_360 {
27
6
28
7
publicstaticclassSolution1 {
@@ -37,12 +16,12 @@ public int[] sortTransformedArray(int[] nums, int a, int b, int c) {
37
16
while (i <= j) {
38
17
if (a >= 0) {
39
18
sorted[index--] =
40
-
function(nums[i], a, b, c) >= function(nums[j], a, b, c) ? function(
41
-
nums[i++], a, b, c) : function(nums[j--], a, b, c);
19
+
function(nums[i], a, b, c) >= function(nums[j], a, b, c) ? function(
20
+
nums[i++], a, b, c) : function(nums[j--], a, b, c);
42
21
} else {
43
22
sorted[index++] =
44
-
function(nums[i], a, b, c) >= function(nums[j], a, b, c) ? function(
45
-
nums[j--], a, b, c) : function(nums[i++], a, b, c);
23
+
function(nums[i], a, b, c) >= function(nums[j], a, b, c) ? function(
24
+
nums[j--], a, b, c) : function(nums[i++], a, b, c);
0 commit comments