Skip to content

Commit fd3386a

Browse files
Removed extra loop in Anagram.java (TheAlgorithms#3654)
1 parent 315e947 commit fd3386a

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/main/java/com/thealgorithms/strings/Anagrams.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,8 @@ boolean approach4(String s, String t) {
121121
for (char c : t.toCharArray()) {
122122
kk.put(c, kk.getOrDefault(c, 0) + 1);
123123
}
124-
// It checks for equal frequencies
125-
for (char c : nm.keySet()) {
126-
if (!nm.get(c).equals(kk.get(c))) {
127-
return false;
128-
}
129-
}
130-
return true;
124+
// It checks for equal frequencies by comparing key-value pairs of two hashmaps
125+
return nm.equals(kk);
131126
}
132127
}
133128
}

0 commit comments

Comments
 (0)