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/number-of-1-bits/ | |
class Solution { | |
public: | |
int hammingWeight(uint32_t n) { | |
int size = 32; //uint32 | |
int numOne = 1; | |
int cnt = 0; | |
for(int i=0; i<size ; ++i) { |
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/excel-sheet-column-number/ | |
//Key point: this problem is just 26th-decimal transformation. | |
//input : only capital? no exception? | |
//O(l); l is the length of the given input | |
//test case | |
//A, Z, AA, BB, AAA |
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 |