Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 92b375f

Browse files
committed
Refactor with PMD quickstart
1 parent 4e5f589 commit 92b375f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

‎src/main/java/hackerrank/java/Anagrams.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package hackerrank.java;
22

3-
import hackerrank.java.Anagrams;
4-
53
import java.util.Arrays;
4+
import java.util.Locale;
65

76
public 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;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /