Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 899bb5d

Browse files
committed
No908
1 parent 475ca1d commit 899bb5d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

leetcode/Array/908.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int smallestRangeI(int[] A, int K) {
3+
if(A.length == 0 || A.length == 1){
4+
return 0;
5+
}
6+
//[2,7,2] [2,2,7] K = 1
7+
//[1,3,6] 3
8+
int len = A.length;
9+
Arrays.sort(A);
10+
if(A[len - 1] - A[0] <= 2*K){
11+
return 0;
12+
}else{
13+
return A[len-1] - 2*K - A[0];
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)