Last active
April 28, 2021 06:55
-
-
Save tremaineeto/aa70591e2123a12929e673b7fe5ca8e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void keepCountOfCharactersInString(String str) { | |
HashMap<Character, Integer> map = new HashMap<>(); | |
for (int i = 0; i < str.length(); i++) { | |
if (!map.containsKey(str.charAt(i)) { | |
map.put(str.charAt(i), 1); | |
} else { | |
int currentCount = map.get(str.charAt(i)); | |
currentCount++; | |
map.put(str.charAt(i), currentCount); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment