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
#include <stdio.h> | |
#include <time.h> | |
typedef struct { | |
union { | |
char * company; | |
char * school; | |
char * project; | |
}; | |
union { |
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/search-a-2d-matrix/ | |
/* | |
I think the the most important hint is the fact that this matrix is already sorted. | |
just think of the binary search. | |
I could know the length of each row, thus start from the first element of the middle row(2/n), compare then move to 4/n ... | |
test case1 | |
long column: [1,2,3,4,5,6,7,8,9,10,11,12...] |
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/permutations/ | |
class Solution { | |
public: | |
vector<vector<int>> permute(vector<int> &num) { | |
vector<vector<int>> res; | |
if(num.size() == 0) { | |
return res; | |
} |
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/permutations/ | |
class Solution { | |
public: | |
vector<vector<int>> permute(vector<int> &num) { | |
vector<vector<int>> res; | |
if(num.size() == 0) { | |
return res; | |
} | |
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/binary-tree-level-order-traversal-ii/ | |
/** | |
* Definition for binary tree | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; |
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/unique-paths/ | |
/* | |
let's count the number of cases: | |
m,n=00/10/01 .. 1 | |
m,n=1,1 1 | |
m,n=1,2 1 | |
m,n=1,3 1 | |
m,n=2,1 1 | |
m,n=2,2 (2,1) + (1,2) = 2 |
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/generate-parentheses/ | |
/* | |
"well-formed" 의미를 시작전 명확하게 인터뷰어와 논의. 여기서는 열고( 닫는) 한쌍의 괄호쌍 의미 | |
좀 더 정확하게 정의해보면, 닫힌 괄호가 나왔을때, 앞에 매칭되는 열린괄호가 최소한 1개는 존재해야함. | |
n=1 (), | |
n=2 (()), ()() | |
n=3 ()(()), (()()), ((())), (()()), (())(), ()()() | |
n=4 .. |
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/rotate-image/ | |
/* | |
tese case | |
1 2 3 4 | |
5 6 7 8 | |
9 10 11 12 | |
13 14 15 16 |
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/plus-one/ | |
/* | |
digit binaoperation은 언제나 carry 처리/자릿수 변경이 관건 | |
맨 뒷자리부터 1씩 더해나가면서 carry 처리. | |
O(n) | |
carry 관련 문제는 언제나 loop끝나고 남은 carry를 처리해주는 것을 잊지 말것 | |
001 |
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/remove-duplicates-from-sorted-array/ | |
/* | |
똑같은 문제인 https://oj.leetcode.com/problems/remove-element/의 유사판 | |
16라인 한줄만 고치고 accepted | |
*/ | |
class Solution { | |
public: | |
int removeDuplicates(int A[], int n) { |