Merge pull request #2583 from blueskyson/patch-2

Update 0242: Add C solution
This commit is contained in:
程序员Carl
2024-06-19 10:36:09 +08:00
committed by GitHub

View File

@ -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)