Merge pull request #488 from evandronmota/master

Add LeetCode 231
This commit is contained in:
Hai Hoang Dang 2019-10-28 15:39:44 -07:00 committed by GitHub
commit ca5da0e61e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -52,7 +52,9 @@ LeetCode
|215|[Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/) | [C](./src/215.c)|Medium|
|217|[Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | [C](./src/217.c)|Easy|
|226|[Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/) | [C](./src/226.c)|Easy|
|231|[Power of Two](https://leetcode.com/problems/power-of-two/) | [C](./src/231.c)|Easy|
|234|[Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/) | [C](./src/234.c)|Easy|
|242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [C](./src/242.c)|Easy|
|268|[Missing Number](https://leetcode.com/problems/missing-number/) | [C](./src/268.c)|Easy|
|278|[First Bad Version](https://leetcode.com/problems/first-bad-version/) | [C](./src/278.c)|Easy|
|283|[Move Zeroes](https://leetcode.com/problems/move-zeroes/) | [C](./src/283.c)|Easy|

5
leetcode/src/231.c Normal file
View File

@ -0,0 +1,5 @@
bool isPowerOfTwo(int n){
if (! n) return false;
while (n % 2 == 0) n /= 2;
return n == 1;
}

20
leetcode/src/242.c Normal file
View File

@ -0,0 +1,20 @@
bool isAnagram(char * s, char * t){
int n = strlen(s);
int m = strlen(t);
int cnt_s[1000], cnt_t[1000];
for (int c = 97; c < 97 + 26; c++)
cnt_s[c] = cnt_t[c] = 0;
for (int i = 0; i < n; i++)
cnt_s[s[i]]++;
for (int i = 0; i < m; i++)
cnt_t[t[i]]++;
for (int c = 97; c < 97 + 26; c++)
if (cnt_s[c] != cnt_t[c])
return false;
return true;
}