8000 update · githubcs/Java-Coding-Problems@d62a275 · GitHub
[go: up one dir, main page]

Skip to content

Commit d62a275

Browse files
committed
update
1 parent b720784 commit d62a275

File tree

1 file changed

+1
-6
lines changed
  • Chapter_01/P02_FirstNonRepeatedCharacter/src/modern/challenge

1 file changed

+1
-6
lines changed

Chapter_01/P02_FirstNonRepeatedCharacter/src/modern/challenge/Strings.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ public static char firstNonRepeatedCharacterV3(String str) {
8686
for (int i = 0; i < str.length(); i++) {
8787
char ch = str.charAt(i);
8888

89-
Integer count = chars.get(ch);
90-
if (count == null) {
91-
chars.put(ch, 1);
92-
} else {
93-
chars.put(ch, ++count);
94-
}
89+
chars.compute(ch, (k, v) -> (v == null) ? 1 : ++v);
9590
}
9691

9792
for (Map.Entry<Character, Integer> entry : chars.entrySet()) {

0 commit comments

Comments
 (0)
0