摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?confused what "{1,#,2,3}" means? > read more on how binary tree is se 阅读全文
posted @ 2013-08-11 22:51 冰点猎手 阅读(344) 评论(0) 推荐(0)
摘要: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1return[ [5,4,11,2... 阅读全文
posted @ 2013-08-11 20:22 冰点猎手 阅读(162) 评论(0) 推荐(0)
摘要: Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra space.For example,Given the following binary tree, 1 / \ 2 3 / \ \ 4 5 ... 阅读全文
posted @ 2013-08-11 19:58 冰点猎手 阅读(205) 评论(0) 推荐(0)
摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.Initially, all next pointers are set to NULL... 阅读全文
posted @ 2013-08-11 19:19 冰点猎手 阅读(205) 评论(0) 推荐(0)
摘要: Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space? class Solution {public: vector getRow(int rowIndex) { // Start typing your C/C++ solution below // DO NOT wri... 阅读全文
posted @ 2013-08-11 16:53 冰点猎手 阅读(177) 评论(0) 推荐(0)
摘要: Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]] class Solution {public: vector > generate(int numRows) { // Start typing your C/C++ solution below // DO NOT write int main()... 阅读全文
posted @ 2013-08-11 16:33 冰点猎手 阅读(165) 评论(0) 推荐(0)
摘要: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).Note:Bonus point if... 阅读全文
posted @ 2013-08-11 16:23 冰点猎手 阅读(206) 评论(0) 推荐(0)
摘要: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome.Note:Have you consider that the string might be empty? This is a good questio 阅读全文
posted @ 2013-08-11 15:57 冰点猎手 阅读(206) 评论(0) 推荐(0)
摘要: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-leaf path 1->2 represents the num 阅读全文
posted @ 2013-08-11 15:26 冰点猎手 阅读(175) 评论(0) 推荐(0)
摘要: Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X XX O O XX X O XX O X XAfter running your function, the board should be:X X X XX X X 阅读全文
posted @ 2013-08-11 15:11 冰点猎手 阅读(173) 评论(0) 推荐(0)