File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed
src/main/java/hackerrank/java Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change 11package hackerrank .java ;
22
3- import hackerrank .java .Anagrams ;
4-
53import java .util .Arrays ;
4+ import java .util .Locale ;
65
76public class Anagrams {
87 String first ;
@@ -15,20 +14,22 @@ public Anagrams(String first, String second) {
1514
1615 public boolean isAnagram () {
1716
18- if (first .length () != second .length ())
17+ if ( first .length () != second .length () ) {
1918 return false ;
20-
21- // sort
22- char [] firstCharArr = first .toUpperCase ().toCharArray ();
23- char [] secondCharArr = second .toUpperCase ().toCharArray ();
19+ }
20+ Locale locale = Locale .ENGLISH ;
21+ String firstUpper = first .toUpperCase (locale );
22+ String secondUpper = second .toUpperCase (locale );
23+ char [] firstCharArr = firstUpper .toCharArray ();
24+ char [] secondCharArr = secondUpper .toCharArray ();
2425 Arrays .sort (firstCharArr );
2526 Arrays .sort (secondCharArr );
2627
27- // compare all the characters
28- for (int i =0 ; i <first .length (); i ++){
28+ for (int i =0 ; i < first .length (); i ++) {
2929
30- if ( firstCharArr [i ] != secondCharArr [i ])
30+ if ( firstCharArr [i ] != secondCharArr [i ] ) {
3131 return false ;
32+ }
3233 }
3334
3435 return true ;
You can’t perform that action at this time.
0 commit comments