上一页 1 2 3 4 5 6 7 8 9 10 ··· 14 下一页
摘要: 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. 1 class S 阅读全文
posted @ 2014-03-19 19:21 小菜刷题史 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example,Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of 阅读全文
posted @ 2014-03-19 19:00 小菜刷题史 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.A partially filled sudoku which is valid.Note:A valid Sudoku board (partially filled) is not necessarily solvable. Only the f 阅读全文
posted @ 2014-03-19 14:10 小菜刷题史 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],] 1 class Solution { 2 public: 3 vector > combine(int n, int k) { 4 vector> result; 5 vector used(n + 1, f... 阅读全文
posted @ 2014-03-19 13:23 小菜刷题史 阅读(238) 评论(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]. 1 class Solution { 2 public: 3 vector > permuteUnique(vector &num) { 4 vector > result; 5 so... 阅读全文
posted @ 2014-03-19 12:49 小菜刷题史 阅读(154) 评论(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]. 1 class Solution { 2 public: 3 vector > permute(vector &num) { 4 vector > result; 5 sort(num.begin(), num.end())... 阅读全文
posted @ 2014-03-18 16:35 小菜刷题史 阅读(168) 评论(0) 推荐(0) 编辑
摘要: The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123""132""213""231""312""321"Givennandk, return thekthpermutation sequence.Not 阅读全文
posted @ 2014-03-18 16:06 小菜刷题史 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory.He 阅读全文
posted @ 2014-03-18 13:09 小菜刷题史 阅读(274) 评论(0) 推荐(0) 编辑
摘要: Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length. 1 class Solution { 2 public: 3 int removeElement(int A[], int n, int elem) { 4 int i = 0; 5 ... 阅读全文
posted @ 2014-03-17 22:44 小菜刷题史 阅读(83) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d)The solution set must not contain duplicate quadruplets. . 阅读全文
posted @ 2014-03-17 22:35 小菜刷题史 阅读(216) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 14 下一页