From 62ec2e7a9a325897030757320093e4fdc306eb59 Mon Sep 17 00:00:00 2001 From: Lswiggard <78099004+Lswiggard@users.noreply.github.com> Date: Fri, 28 Apr 2023 12:54:47 -0400 Subject: [PATCH] Made Changes I changed the booleans to integers --- Anagram.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Anagram.java b/Anagram.java index fb62b57..b7cff72 100644 --- a/Anagram.java +++ b/Anagram.java @@ -2,13 +2,23 @@ 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); + if (oneHM.containsKey(c)) { + oneHM.put(c, oneHM.get(c) + 1); + } + else + oneHM.put(c, 1); } + for (char c : twoS.toCharArray()) { - twoHM.put(c, true); + if (twoHM.containsKey(c)) { + twoHM.put(c, twoHM.get(c) + 1); + + } + else + twoHM.put(c, 1); } return oneHM.equals(twoHM); } @@ -16,4 +26,5 @@ public static boolean anagram(String oneS, String twoS) { public static void main(String[] args) { System.out.println(anagram(args[0], args[1])); } + // changes made }