Skip to content

Commit 8997f68

Browse files
solves smallest range I
1 parent 4c10c78 commit 8997f68

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | [![Java](assets/java.png)](src/MonotonicArray.java) |
246246
| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | [![Java](assets/java.png)](src/IncreasingOrderSearchTree.java) |
247247
| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | |
248-
| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | |
248+
| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | [![Java](assets/java.png)](src/SmallestRangeI.java) |
249249
| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | |
250250
| 917 | [Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters) | |
251251
| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | |

src/SmallestRangeI.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.util.Arrays;
2+
3+
public class SmallestRangeI {
4+
public int smallestRangeI(int[] nums, int k) {
5+
return Math.max(
6+
0,
7+
Arrays.stream(nums).max().getAsInt() - Arrays.stream(nums).min().getAsInt() - 2 * k
8+
);
9+
}
10+
}

0 commit comments

Comments
 (0)