Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5fd40fc

Browse files
committed
Minor improvement
1 parent 24fe946 commit 5fd40fc

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

‎src/main/java/com/leetcode/maps/slidingwindow/LongestSubstringWithKDistinctCharacters.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public static int lengthOfLongestSubstringKDistinct(String str, int k) {
4444
while (j < str.length()) {
4545
char ch = str.charAt(j);
4646

47-
letterCountInWindow.putIfAbsent(ch, 0);
48-
letterCountInWindow.put(ch, letterCountInWindow.get(ch) + 1);
47+
letterCountInWindow.put(ch, letterCountInWindow.getOrDefault(ch, 0) + 1);
4948

5049
// when number of distinct characters in the window exceeds k:
5150
// - update length

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /