This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"event": "push", | |
"payload": { | |
"ref": "refs/heads/master", | |
"before": "1214900eca16aa54d97d062e7b72261616fd53aa", | |
"after": "40a717b3644e2ddec52cf6c8bfa436767bf0704e", | |
"repository": { | |
"id": 17892893, | |
"node_id": "MDEwOlJlcG9zaXRvcnkxNzg5Mjg5Mw==", | |
"name": "codecombat", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#1. Given the string of parentheses only, write the function to check if they are balanced. | |
((())) is balanced, | |
(() is not. | |
)( not balanced | |
bool isBalanced(char input[]) { | |
Stack stack; | |
int len = strlen(input); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://oj.leetcode.com/problems/minimum-path-sum/ | |
/* | |
초기 접근: | |
전수조사를 해야하는가->그렇다. | |
어떻게 가지치기 할 것인가-> dp 적용 | |
base case 설정: | |
if left == m-1, down == n-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//assume object is int | |
int findMajority(vector<int> input) { | |
vector<int> temp; | |
if (input.size() == 0) return NOMAJORITY; | |
else if (input.size() == 1) return input[0]; | |
else if (input.size() == 2) { | |
if (input[0] == input[1]) return input[0]; | |
else return NOMAJORITY; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Node | |
{ | |
int score; | |
Node* left; | |
Node* right; | |
}; | |
//M(r,k) returns the maximum sum of score of size k from root r. M(r,k) = max( M(l,i), M(r,j)); i+j = k and i,j>0 | |
int findMaxScore(Node* node, int k) { | |
vector<int> sum; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://leetcode.com/problems/happy-number/ | |
For cycle detection: | |
1. Floyd's tortoise and rabbit algorithm (two pointers; slow and fast) | |
2. Brant's algorithm | |
3. using Hash table to detect duplicated values; | |
*/ | |
class Solution { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://leetcode.com/problems/palindrome-number/ | |
exception case : negative, zero | |
filter x < 0 || X < 10 || x % 10 | |
create int y by traversing x in reverse order | |
x = 12321, y = 0 | |
y = 1=>12=>123=>1232=>12321 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://leetcode.com/problems/container-with-most-water/ | |
Did I clearly understand the problem? | |
Is the given input is sorted? No | |
| | | |
| | | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://leetcode.com/problems/find-peak-element/ | |
O(log n) | |
key point: getting a sense of that current maximum is a strong nominate of local maximum. | |
1. pick middle of the give subarray | |
2. compare both neighbor of current maximum | |
3. ignore smaller side. (why? -> current maximum could be a local maximum) | |
4. 1->3 iterate until the length of the given subarray is less than 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ | |
//Linear search: O(n) | |
class Solution { | |
public: | |
int findMin(vector<int> &num) { | |
int min = INT_MAX; | |
NewerOlder