Skip to content

Commit a9de6a6

Browse files
committed
refactor: valid anagram - map.values()
1 parent 895e6b2 commit a9de6a6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

valid-anagram/minji-go.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description: return true if one string is an anagram of the other, one formed by rearranging the letters of the other
44
Concept:String, Hash Table, Sorting, Array, Counting, String Matching, Ordered Map, Ordered Set, Hash Function ...
55
Time Complexity: O(n), Runtime: 27ms
6-
Space Complexity: O(n), Memory: 43.11MB
6+
Space Complexity: O(n), Memory: 43.05MB
77
*/
88
import java.util.HashMap;
99
import java.util.Map;
@@ -12,13 +12,13 @@ class Solution {
1212
public boolean isAnagram(String s, String t) {
1313
if(s.length() != t.length()) return false;
1414

15-
Map<Character, Integer> count = new HashMap<>();
15+
Map<Character, Integer> charCount = new HashMap<>();
1616
for(int i=0; i<s.length(); i++){
17-
count.put(s.charAt(i), count.getOrDefault(s.charAt(i), 0)+1);
18-
count.put(t.charAt(i), count.getOrDefault(t.charAt(i), 0)-1);
17+
charCount.put(s.charAt(i), charCount.getOrDefault(s.charAt(i), 0)+1);
18+
charCount.put(t.charAt(i), charCount.getOrDefault(t.charAt(i), 0)-1);
1919
}
20-
for(Character key : count.keySet()){
21-
if(count.get(key)!=0) return false;
20+
for(Integer count : charCount.values()){
21+
if(count !=0) return false;
2222
}
2323
return true;
2424
}

0 commit comments

Comments
 (0)