Skip to content

Commit f9403c2

Browse files
committed
Runtime: 11 ms (Top 6.67%) | Memory: 47.2 MB (Top 65.28%)
1 parent 864b4d3 commit f9403c2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1+
// Runtime: 11 ms (Top 6.67%) | Memory: 47.2 MB (Top 65.28%)
12
class Solution {
23
int max = 0;
34
int len;
45
public int findBestValue(int[] arr, int target) {
56
this.len = arr.length;
6-
7+
78
for (int i = 0; i < len; i++)
89
max = Math.max(max, arr[i]);
9-
10+
1011
int l = 0;
1112
int r = max;
1213
while(l < r){
1314
int mid = l + (r-l) / 2;
14-
15+
1516
if(check(arr, mid, target) <= check(arr, mid+1, target))
1617
r = mid;
1718
else
1819
l = mid + 1;
1920
}
2021
return l;
2122
}
22-
23+
2324
private int check(int[] arr, int value, int target){
2425
int sum = 0;
2526
for(int e : arr){
@@ -28,7 +29,7 @@ private int check(int[] arr, int value, int target){
2829
else
2930
sum += e;
3031
}
31-
32+
3233
return Math.abs(sum-target);
3334
}
34-
}
35+
}

0 commit comments

Comments
 (0)