8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b720784 commit d62a275Copy full SHA for d62a275
Chapter_01/P02_FirstNonRepeatedCharacter/src/modern/challenge/Strings.java
@@ -86,12 +86,7 @@ public static char firstNonRepeatedCharacterV3(String str) {
86
for (int i = 0; i < str.length(); i++) {
87
char ch = str.charAt(i);
88
89
- Integer count = chars.get(ch);
90
- if (count == null) {
91
- chars.put(ch, 1);
92
- } else {
93
- chars.put(ch, ++count);
94
- }
+ chars.compute(ch, (k, v) -> (v == null) ? 1 : ++v);
95
}
96
97
for (Map.Entry<Character, Integer> entry : chars.entrySet()) {
0 commit comments