mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge pull request #2583 from blueskyson/patch-2
Update 0242: Add C solution
This commit is contained in:
@ -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)
|
||||||
|
Reference in New Issue
Block a user