Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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
https://oj.leetcode.com/problems/plus-one/
/*
digit binaoperation은 언제나 carry 처리/자릿수 변경이 관건
맨 뒷자리부터 1씩 더해나가면서 carry 처리.
O(n)
carry 관련 문제는 언제나 loop끝나고 남은 carry를 처리해주는 것을 잊지 말것
001
@walkingtospace
walkingtospace / gist:aa68010f8da1c9331451
Created August 28, 2014 01:52
remove-duplicates-from-sorted-array
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) {