mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-02-02 18:39:09 +08:00
Merge branch 'master' into master
This commit is contained in:
@@ -88,19 +88,19 @@ Java:
|
||||
```java
|
||||
class Solution {
|
||||
public boolean isAnagram(String s, String t) {
|
||||
int[] strMap = new int[123];
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
strMap[s.charAt(i) + 0]++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < t.length(); i++) {
|
||||
strMap[t.charAt(i) + 0]--;
|
||||
int[] record = new int[26];
|
||||
for (char c : s.toCharArray()) {
|
||||
record[c - 'a'] += 1;
|
||||
}
|
||||
|
||||
for (int i = 90; i < 123; i++) {
|
||||
if (strMap[i] != 0) return false;
|
||||
for (char c : t.toCharArray()) {
|
||||
record[c - 'a'] -= 1;
|
||||
}
|
||||
for (int i : record) {
|
||||
if (i != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user