Skip to content

Commit c62508b

Browse files
refactor 360
1 parent e63e892 commit c62508b

File tree

1 file changed

+4
-25
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-25
lines changed

src/main/java/com/fishercoder/solutions/_360.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,6 @@
22

33
import java.util.Arrays;
44

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-
*/
265
public class _360 {
276

287
public static class Solution1 {
@@ -37,12 +16,12 @@ public int[] sortTransformedArray(int[] nums, int a, int b, int c) {
3716
while (i <= j) {
3817
if (a >= 0) {
3918
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);
4221
} else {
4322
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);
4625
}
4726
}
4827
return sorted;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy