摘要: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code s 阅读全文
posted @ 2012-11-26 21:44 chkkch 阅读(2321) 评论(1) 推荐(1) 编辑
摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6Hints:If you notice carefully ... 阅读全文
posted @ 2012-11-26 21:39 chkkch 阅读(1363) 评论(0) 推荐(0) 编辑
摘要: Divide two integers without using multiplication, division and mod operator. 1 class Solution { 2 private: 3 long long f[100]; 4 public: 5 int bsearch(long long a[], int left, int right, long long key) 6 { 7 if (left > right) 8 return -1; 9 10 int ... 阅读全文
posted @ 2012-11-26 21:23 chkkch 阅读(1187) 评论(0) 推荐(0) 编辑
摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack. 1 class Solution { 2 public: 3 char *strStr(char *haystack, char *needle) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() functi... 阅读全文
posted @ 2012-11-26 20:51 chkkch 阅读(1886) 评论(0) 推荐(0) 编辑
摘要: 题目:二叉树的结点定义如下:structTreeNode{intm_nvalue;TreeNode* m_pLeft;TreeNode* m_pRight;};输入二叉树中的两个结点,输出这两个结点在数中最低的共同父结点。递归版本:空间O(1),时间O(n) 1 struct Node 2 { 3 int val; 4 Node *left; 5 Node *right; 6 Node():left(NULL), right(NULL){} 7 }; 8 9 Node *findFather(Node *root, Node *node1, Node *nod... 阅读全文
posted @ 2012-11-26 12:01 chkkch 阅读(1194) 评论(0) 推荐(2) 编辑