Skip to content

Commit b981623

Browse files
authored
Update Solution.java
1 parent 1106d76 commit b981623

File tree

1 file changed

+3
-12
lines changed
  • src/main/java/g1701_1800/s1755_closest_subsequence_sum

1 file changed

+3
-12
lines changed

src/main/java/g1701_1800/s1755_closest_subsequence_sum/Solution.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,30 @@ public class Solution {
1111

1212
public int minAbsDifference(int[] nums, int goal) {
1313
int n = nums.length;
14-
1514
int nFirst = (int) Math.pow(2, (double) n / 2);
1615
int nSecond = (int) Math.pow(2, n - n / 2);
17-
1816
int[] first = new int[nFirst];
1917
int[] second = new int[nSecond];
20-
2118
helper(nums, first, 0, n / 2 - 1);
2219
idx = sum = 0;
2320
helper(nums, second, n / 2, n - 1);
24-
2521
Arrays.sort(first);
2622
Arrays.sort(second);
27-
2823
int low = 0;
2924
int high = nSecond - 1;
30-
3125
int ans = Integer.MAX_VALUE;
3226
while (low < nFirst && high >= 0) {
33-
int sum = first[low] + second[high];
34-
ans = Math.min(ans, Math.abs(sum - goal));
35-
27+
int localSum = first[low] + second[high];
28+
ans = Math.min(ans, Math.abs(localSum - goal));
3629
if (ans == 0) {
3730
break;
3831
}
39-
40-
if (sum < goal) {
32+
if (localSum < goal) {
4133
low++;
4234
} else {
4335
high--;
4436
}
4537
}
46-
4738
return ans;
4839
}
4940

0 commit comments

Comments
 (0)