正文内容加载中...
posted @ 2013-11-01 09:56 remlostime 阅读(3133) 评论(16) 编辑
摘要: Problem StatementCucumber Boy likes drawing pictures. Today, he plans to draw a picture using a very simple graphics editor.The editor has the following functions:The canvas is an infinite two-dimensional grid of pixels.There are only two colors: black, and transparent. These are denoted 'B'阅读全文
posted @ 2012-12-02 14:45 remlostime 阅读(190) 评论(0) 编辑
摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6. 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *rig...阅读全文
posted @ 2012-12-02 14:05 remlostime 阅读(1520) 评论(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again). 1 class So阅读全文
posted @ 2012-11-29 19:35 remlostime 阅读(1347) 评论(0) 编辑
摘要: Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype should be:bool i阅读全文
posted @ 2012-11-27 10:23 remlostime 阅读(860) 评论(0) 编辑
摘要: 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 remlostime 阅读(1625) 评论(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 remlostime 阅读(901) 评论(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 remlostime 阅读(666) 评论(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 remlostime 阅读(1024) 评论(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 remlostime 阅读(354) 评论(0) 编辑