From 17b18e1b3c33f92fd1eed4b14e16c3b1f565281a Mon Sep 17 00:00:00 2001 From: TippyToo Date: Fri, 28 Apr 2023 13:09:26 -0400 Subject: [PATCH] fixed bug --- Anagram.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Anagram.java b/Anagram.java index fb62b57..332d107 100644 --- a/Anagram.java +++ b/Anagram.java @@ -2,13 +2,13 @@ public class Anagram { public static boolean anagram(String oneS, String twoS) { - HashMap oneHM = new HashMap(); - HashMap twoHM = new HashMap(); + HashMap oneHM = new HashMap(); + HashMap twoHM = new HashMap(); for (char c : oneS.toCharArray()) { - oneHM.put(c, true); + oneHM.put(c, oneHM.getOrDefault(c, 0)+1); } for (char c : twoS.toCharArray()) { - twoHM.put(c, true); + twoHM.put(c, twoHM.getOrDefault(c, 0)+1); } return oneHM.equals(twoHM); }