Skip to content

Instantly share code, notes, and snippets.

Honam Bahng walkingtospace

Block or report user

Report or block walkingtospace

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:80fc2f995431226bfe7b
//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;
View gist:6a739eb80e6344591dcf
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;
View gist:5fa181ee4f83bd4201e4
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 {
View gist:cf101d46903b71e01f18
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
View gist:16d0ebd52929374411c5
Did I clearly understand the problem?
Is the given input is sorted? No
| |
| | | |
View gist:b1a3719713be50d456c6
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
walkingtospace / gist:f58ac0f00668646586d4
Created Apr 2, 2015
View gist:f58ac0f00668646586d4
//Linear search: O(n)
class Solution {
int findMin(vector<int> &num) {
int min = INT_MAX;
View gist:bc863d29f1f0924afca8
class Solution {
int hammingWeight(uint32_t n) {
int size = 32; //uint32
int numOne = 1;
int cnt = 0;
for(int i=0; i<size ; ++i) {
walkingtospace / gist:b7ccdabf3f5c317da76e
Last active Aug 29, 2015
Excel sheet column number
View gist:b7ccdabf3f5c317da76e
//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
View resume.c
#include <stdio.h>
#include <time.h>
typedef struct {
union {
char * company;
char * school;
char * project;
union {
You can’t perform that action at this time.