摘要:
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 阅读全文
摘要:
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.思路:典型的动态规划问题。result[i][j]表示(0,0)到(i,j)的最小值。result[i][j]=min(result[i][j-1],result[i-1][j])+g 阅读全文
摘要:
Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"思路:这道题给你n对括号,生成所有合法的括号规则。有如下规则:左括号和右括号的数量都为n时,将生成的括号push到re 阅读全文