Update 0242: Add C solution
This commit is contained in:
parent
70643a80a0
commit
0f6ea64f68
|
|
@ -383,6 +383,31 @@ object Solution {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### C
|
||||||
|
|
||||||
|
```c
|
||||||
|
bool isAnagram(char* s, char* t) {
|
||||||
|
int len1 = strlen(s), len2 = strlen(t);
|
||||||
|
if (len1 != len2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int map1[26] = {0}, map2[26] = {0};
|
||||||
|
for (int i = 0; i < len1; i++) {
|
||||||
|
map1[s[i] - 'a'] += 1;
|
||||||
|
map2[t[i] - 'a'] += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 26; i++) {
|
||||||
|
if (map1[i] != map2[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 相关题目
|
## 相关题目
|
||||||
|
|
||||||
* [383.赎金信](https://programmercarl.com/0383.%E8%B5%8E%E9%87%91%E4%BF%A1.html)
|
* [383.赎金信](https://programmercarl.com/0383.%E8%B5%8E%E9%87%91%E4%BF%A1.html)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue