We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 315e947 commit fd3386aCopy full SHA for fd3386a
src/main/java/com/thealgorithms/strings/Anagrams.java
@@ -121,13 +121,8 @@ boolean approach4(String s, String t) {
121
for (char c : t.toCharArray()) {
122
kk.put(c, kk.getOrDefault(c, 0) + 1);
123
}
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;
+ // It checks for equal frequencies by comparing key-value pairs of two hashmaps
+ return nm.equals(kk);
131
132
133
0 commit comments