Removed extra loop in Anagram.java (#3654)
This commit is contained in:
parent
315e947c87
commit
fd3386a0db
@ -121,13 +121,8 @@ public class Anagrams {
|
||||
for (char c : t.toCharArray()) {
|
||||
kk.put(c, kk.getOrDefault(c, 0) + 1);
|
||||
}
|
||||
// It checks for equal frequencies
|
||||
for (char c : nm.keySet()) {
|
||||
if (!nm.get(c).equals(kk.get(c))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
// It checks for equal frequencies by comparing key-value pairs of two hashmaps
|
||||
return nm.equals(kk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user