Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd2429c

Browse files
Java Solution for 242 Valid Anagram
1 parent 603e0a1 commit cd2429c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

java/242-Valid-Anagram.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public boolean isAnagram(String s, String t) {
3+
if (s.length() != t.length()) return false;
4+
5+
int[] countS = new int[26];
6+
int[] countT = new int[26];
7+
8+
for (int i = 0 ; i < s.length() ; i++) {
9+
countS[s.charAt(i) - 'a']++;
10+
countT[t.charAt(i) - 'a']++;
11+
}
12+
13+
for (int i = 0 ; i < 26 ; i++) {
14+
if (countS[i] - countT[i] != 0) return false;
15+
}
16+
17+
return true;
18+
}
19+
}

0 commit comments

Comments
 (0)