Skip to content

Instantly share code, notes, and snippets.

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) {
@walkingtospace
walkingtospace / gist:b7ccdabf3f5c317da76e
Last active August 29, 2015 14:18
Excel sheet column number
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
@walkingtospace
walkingtospace / resume.c
Last active August 29, 2015 14:17 — forked from klange/_.md
#include <stdio.h>
#include <time.h>
typedef struct {
union {
char * company;
char * school;
char * project;
};
union {
@walkingtospace
walkingtospace / gist:dc7ec9fd8951ff52fc8d
Last active August 29, 2015 14:06
search-a-2d-matrix
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...]
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;
}
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;
}
@walkingtospace
walkingtospace / gist:63f8c98fb34d6463ec0f
Last active August 29, 2015 14:06
binary-tree-level-order-traversal-ii
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) {}
* };
@walkingtospace
walkingtospace / gist:77abc84ea41c14a3439c
Created September 14, 2014 20:54
unique-paths with dynamic programming
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
@walkingtospace
walkingtospace / gist:b07cb7515faabd82b2fb
Last active August 29, 2015 14:06
generate-parentheses
https://oj.leetcode.com/problems/generate-parentheses/
/*
"well-formed" 의미를 시작전 명확하게 인터뷰어와 논의. 여기서는 열고( 닫는) 한쌍의 괄호쌍 의미
좀 더 정확하게 정의해보면, 닫힌 괄호가 나왔을때, 앞에 매칭되는 열린괄호가 최소한 1개는 존재해야함.
n=1 (),
n=2 (()), ()()
n=3 ()(()), (()()), ((())), (()()), (())(), ()()()
n=4 ..
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