上一页 1 ··· 3 4 5 6 7 8 9 10 11 12 下一页
摘要: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Solution:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x... 阅读全文
posted @ 2014-03-07 14:19 xchangcheng 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-leaf path1->2represents the number12.T 阅读全文
posted @ 2014-03-07 14:11 xchangcheng 阅读(135) 评论(0) 推荐(0) 编辑
摘要: Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.Note:You are not suppose to use the l 阅读全文
posted @ 2014-02-19 16:26 xchangcheng 阅读(253) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.Note:Givennwill always be valid.Try to do this in one pass.解题 阅读全文
posted @ 2014-01-16 09:27 xchangcheng 阅读(137) 评论(0) 推荐(0) 编辑
摘要: Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, note the restriction of using extra space.You could also try reversing an integer. However, if you have solved 阅读全文
posted @ 2013-12-12 00:05 xchangcheng 阅读(120) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.Note: You 阅读全文
posted @ 2013-11-13 10:31 xchangcheng 阅读(447) 评论(0) 推荐(1) 编辑
摘要: Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(k) extra space?class Solution {public: vector getRow(int rowIndex) { // IMPORTANT: Please reset any member data you declared, as // the same ... 阅读全文
posted @ 2013-11-12 19:43 xchangcheng 阅读(137) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ... 阅读全文
posted @ 2013-11-12 13:26 xchangcheng 阅读(221) 评论(0) 推荐(0) 编辑
摘要: Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.For example,Consider the following matrix:[ [1, 3, ... 阅读全文
posted @ 2013-11-12 12:23 xchangcheng 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Given a number represented as an array of digits, plus one to the number.class Solution {public: vector plusOne(vector &digits) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. int a = 1; vec... 阅读全文
posted @ 2013-11-12 12:13 xchangcheng 阅读(655) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 12 下一页