摘要: Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at any point in time.水 1 class Solution { 2 public: 3 int minPathSum(vector > &grid) { 4 int m = grid... 阅读全文
posted @ 2014-03-31 21:53 Eason Liu 阅读(132) 评论(0) 推荐(0) 编辑
摘要: A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文
posted @ 2014-03-31 19:18 Eason Liu 阅读(126) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as1and0respectively in the grid.For example,There is one obstacle in the middle of a 3x3 grid as illustrated below.[ [0,0,0], [0,1, 阅读全文
posted @ 2014-03-31 19:16 Eason Liu 阅读(149) 评论(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 andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1return[ [5,4,11,2]... 阅读全文
posted @ 2014-03-31 01:16 Eason Liu 阅读(132) 评论(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 @ 2014-03-31 01:08 Eason Liu 阅读(147) 评论(0) 推荐(0) 编辑
摘要: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.大数乘法,注意前置0的处理。 1 class Solution { 2 public: 3 string multiply(string num1, string num2) { 4 string num3; 5 num3.resize(num1.s... 阅读全文
posted @ 2014-03-31 00:58 Eason Liu 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo... 阅读全文
posted @ 2014-03-30 23:55 Eason Liu 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2,1,1].注意不能用n!来判断了,可以先排一下序,当序列逆序时结束。 1 class Solution { 2 public: 3 bool nextPermutation(vector &num) { 4 if... 阅读全文
posted @ 2014-03-29 14:23 Eason Liu 阅读(205) 评论(0) 推荐(0) 编辑
摘要: Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].与Next Permutation一样,n个元素的排列共有n!个,所以只要执行n!次next_permutation就行。 1 class Solution { 2 public: 3 bool nextPermutation(vector &num) { 阅读全文
posted @ 2014-03-29 14:16 Eason Liu 阅读(516) 评论(0) 推荐(0) 编辑
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文
posted @ 2014-03-29 13:34 Eason Liu 阅读(3845) 评论(0) 推荐(3) 编辑