摘要: 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) 编辑