File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed
Solved-Problems/Valid_Anagram Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 33
44class Main {
55 public boolean isAnagram (String s , String t ) {
6- if (s .length () != t .length ())
7- {
6+ if (s .length () != t .length ()) {
87 return false ;
98 }
109
1110 Map <Character , Integer > countS = new HashMap <>();
1211 Map <Character , Integer > countT = new HashMap <>();
1312
14- for (int i = 0 ;i <s .length ();i ++)
15- {
13+ for (int i = 0 ; i < s .length (); i ++) {
1614 char c1 = s .charAt (i );
17- countS .put (c1 ,countS .getOrDefault (c1 ,0 )+ 1 );
15+ countS .put (c1 , countS .getOrDefault (c1 , 0 ) + 1 );
1816 }
1917
2018 for (int i = 0 ; i < t .length (); i ++) {
2119 char c2 = t .charAt (i );
2220 countT .put (c2 , countT .getOrDefault (c2 , 0 ) + 1 );
2321 }
2422
25- for (char c : countS .keySet ())
26- {
27- if (!countT .containsKey (c ) || !countT .get (c ).equals (countS .get (c )))
28- {
23+ for (char c : countS .keySet ()) {
24+ if (!countT .containsKey (c ) || !countT .get (c ).equals (countS .get (c ))) {
2925 return false ;
3026 }
31- }
27+ }
28+
3229 return true ;
3330 }
3431}
You can’t perform that action at this time.
0 commit comments