We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 70d67e8 + 3f96750 commit 41cf322Copy full SHA for 41cf322
problems/0242.有效的字母异位词.md
@@ -92,18 +92,24 @@ public:
92
93
Java:
94
```java
95
+/**
96
+ * 242. 有效的字母异位词 字典解法
97
+ * 时间复杂度O(m+n) 空间复杂度O(1)
98
+ */
99
class Solution {
100
public boolean isAnagram(String s, String t) {
-
101
int[] record = new int[26];
- for (char c : s.toCharArray()) {
- record[c - 'a'] += 1;
102
+
103
+ for (int i = 0; i < s.length(); i++) {
104
+ record[s.charAt(i) - 'a']++;
105
}
- for (char c : t.toCharArray()) {
- record[c - 'a'] -= 1;
106
107
+ for (int i = 0; i < t.length(); i++) {
108
+ record[t.charAt(i) - 'a']--;
109
- for (int i : record) {
- if (i != 0) {
110
111
+ for (int count: record) {
112
+ if (count != 0) {
113
return false;
114
115
0 commit comments