Skip to content

Commit

Permalink
Merge pull request #488 from evandronmota/master
Browse files Browse the repository at this point in the history
Add LeetCode 231
  • Loading branch information
danghai authored Oct 28, 2019
2 parents 2e692ed + aaa8a31 commit ca5da0e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions leetcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
5 changes: 5 additions & 0 deletions leetcode/src/231.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bool isPowerOfTwo(int n){
if (! n) return false;
while (n % 2 == 0) n /= 2;
return n == 1;
}
20 changes: 20 additions & 0 deletions leetcode/src/242.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit ca5da0e

Please sign in to comment.