-
Recent Posts
Archives
- July 2016
- June 2016
- May 2016
- March 2016
- January 2016
- November 2015
- October 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- October 2013
- September 2013
- August 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- April 2011
- March 2011
- February 2011
Categories
My Tags
My Profile
Senior Software Engineer At Actuate
Meta
Tag Archives: algorithms
reverse word in a string
question Given an input string, reverse the string word by word. For example, Given s = “the sky is blue”, return “blue is sky the”. click to show clarification. Clarification: What constitutes a word? A sequence of non-space characters constitutes … Continue reading
check if a sequence is a output sequence of a stack or not
assume you have a stack, you have a sequence A[n] : {1,2,3,4,5}, check if sequence B[n] : {5,4,3,2,1} is an output of stack or not. A : 1 2 3 4 5 B : 5 4 3 2 1 … Continue reading
the core algorithm of k-way merge
the code below is excerpt from an algorithm blog. This code snippet is the core algorithm of k-way merge, 1: while(true) 2: { 3: //求data中可用的最小的数字,并记录对应文件的索引 4: int min = data[0]; 5: // j 是文件索引 6: int j = 0; 7: … Continue reading
A very concise solution for leetcode word ladder issue
here is the code, pretty concise, using bfs : class Solution { public: int ladderLength(string start, string end, unordered_set<string> &dict) { queue<pair<string, int>> q; q.push(make_pair(start, 1)); while (!q.empty()) { pair<string, int> front = q.front(); q.pop(); string word = front.first; … Continue reading
3 ways to generate subset
There are several ways to generate a subset, assume you want to generate the subset of (1——n ) : 1. directly put the element to the set code : void print_subset1( int n, int *A, int cur ) { for( … Continue reading
3 ways to enumerate the subset
There are several ways to generate a subset, assume you want to generate the subset of (1——n ) : 1. directly put the element to the set code : void print_subset1( int n, int *A, int cur ) { for( … Continue reading
uva 297 wonderful code for build a quad tree
the problem link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=104&page=show_problem&problem=233 #include #include #include using namespace std ; const int maxn = 2048 + 10 ; struct Node { Node * a ; Node * b ; Node * c ; Node * d ; char data … Continue reading
how to get sum(n) – 2
In my previous post ( link is here ), I post a very interesting question: question: get the sum from 1 to n (n is integer and n >=1). requirements : can not use * (mul) , / (div), bit … Continue reading
Binary Search Tree and Double-linked List
Question: Convert a binary search tree to a sorted double-linked list. We can only change the target of pointers, but cannot create any new nodes.For example, if we input a binary search tree as shown on the left side of … Continue reading
How to get sum(n)
In the forum, I see a very interest post question: get the sum from 1 to n (n is integer and n >=1). requirements : can not use *, /, bit operator, if-else, while, for, switch, ? , ternary operator, … Continue reading