上一页 1 2 3 4 5 6 7 8 ··· 11 下一页
摘要: Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets. For example, If S = [1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]class Sol... 阅读全文
posted @ 2013-07-13 08:22 一只会思考的猪 阅读(161) 评论(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].class Solution {public: vector > ans; void dfs(vector &num,vector &path){ if (path.size() == n.. 阅读全文
posted @ 2013-07-12 08:42 一只会思考的猪 阅读(138) 评论(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].class Solution {public: vector > ans; void dfs(vector &num,vector &path){ if (path.size() == num.size()){ ... 阅读全文
posted @ 2013-07-12 08:23 一只会思考的猪 阅读(157) 评论(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 as 1 and 0 respectively in the grid.For example,There is one obstacle in the middle of a 3x3 grid as illustrated below.[ [0,0,0], [ 阅读全文
posted @ 2013-07-12 07:34 一只会思考的猪 阅读(228) 评论(0) 推荐(0) 编辑
摘要: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).How many possible 阅读全文
posted @ 2013-07-12 07:24 一只会思考的猪 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any point in time.问题:大数据的时候TLE,问题搜索的时候,走了很多重复的子路径所以不能进行DFS(DFS本质上是暴力),而应该DPDP[i,j] = 代表从A[0,0]到A[i,j]的p 阅读全文
posted @ 2013-07-12 07:09 一只会思考的猪 阅读(150) 评论(0) 推荐(0) 编辑
摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { // Start typing your C/C++ solution below // DO NOT write int ma... 阅读全文
posted @ 2013-07-12 06:26 一只会思考的猪 阅读(102) 评论(0) 推荐(0) 编辑
摘要: Given a number represented as an array of digits, plus one to the number.class Solution {public: vector plusOne(vector &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function vector ans; int c = 0, k = 0; for(int i = digits.size(... 阅读全文
posted @ 2013-07-10 22:54 一只会思考的猪 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Implement int sqrt(int x).Compute and return the square root of x.思路:Sqrt(double)需要进行逼近。目前这种方法掌握不好class Solution { public: int sqrt(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function // Start typing your Java solution below... 阅读全文
posted @ 2013-07-10 22:37 一只会思考的猪 阅读(188) 评论(0) 推荐(0) 编辑
摘要: You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?class Solution {public: int climbStairs(int n) { // Start typing your C/C++ solution below // DO NOT write int main() f... 阅读全文
posted @ 2013-07-10 22:09 一只会思考的猪 阅读(137) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 11 下一页