棋子

导航

2016年3月8日 #

Combination Sum

摘要: 题目链接: 回溯算法的剪枝非常重要!! 这个题是一个NP问题,方法仍然是N-Queens中介绍的套路。基本思路是先排好序,然后每次递归中把剩下的元素一一加到结果集合中,并且把目标减去加入的元素,然后把剩下元素(包括当前加入的元素)放到下一层递归中解决子问题。算法复杂度因为是NP问题,所以自然是指数量 阅读全文

posted @ 2016-03-08 21:17 鼬与轮回 阅读(144) 评论(0) 推荐(0) 编辑

2016年3月1日 #

欧几里德算法(辗转相除法)

摘要: 欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数。其计算原理依赖于下面的定理: 定理:gcd(a,b) = gcd(b,a mod b) 欧几里得 证明:a可以表示成a = kb + r,则r = a mod b 假设d是a,b的一个公约数,则有 a % d == 0 , b % d 阅读全文

posted @ 2016-03-01 00:23 鼬与轮回 阅读(647) 评论(0) 推荐(0) 编辑

2016年2月23日 #

求全排列(数组有重复元素和数组无重复元素) 回溯 递归

摘要: http://www.cnblogs.com/TenosDoIt/p/3662644.html 无重复元素 http://blog.csdn.net/havenoidea/article/details/12838479 有重复元素 阅读全文

posted @ 2016-02-23 19:29 鼬与轮回 阅读(391) 评论(0) 推荐(0) 编辑

Count and Say leetcode

摘要: 题目链接 The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11.11 is rea 阅读全文

posted @ 2016-02-23 01:06 鼬与轮回 阅读(196) 评论(0) 推荐(0) 编辑

2016年2月10日 #

Find Minimum in Rotated Sorted Array II leetcode

摘要: 题目链接 这个博客的算法思想简单好! 还是贴上自己的蹩脚代码吧!! 1 class Solution { 2 public: 3 int findMin(vector<int>& nums) { 4 if(nums.empty()) 5 return -1; 6 int begin=0,end=nu 阅读全文

posted @ 2016-02-10 11:11 鼬与轮回 阅读(181) 评论(0) 推荐(0) 编辑

Find Minimum in Rotated Sorted Array leetcode

摘要: 原题链接 直接贴代码,这道题是 search in rotated sorted array leetcode 的前面部分! 1 class Solution { 2 public: 3 int findMin(vector<int>& nums) { 4 if (nums.empty()) 5 r 阅读全文

posted @ 2016-02-10 10:18 鼬与轮回 阅读(149) 评论(0) 推荐(0) 编辑

2016年2月9日 #

Search in Rotated Sorted Array II leetcode

摘要: 原题链接,点我 该题解题参考博客 和Search in Rotated Sorted Array唯一的区别是这道题目中元素会有重复的情况出现。不过正是因为这个条件的出现,出现了比较复杂的case,甚至影响到了算法的时间复杂度。原来我们是依靠中间和边缘元素的大小关系,来判断哪一半是不受rotate影响 阅读全文

posted @ 2016-02-09 23:45 鼬与轮回 阅读(178) 评论(0) 推荐(0) 编辑

search in rotated sorted array leetcode

摘要: 原题链接 题意:给你一个目标值,或者返回其在数组中的下标位置,或者返回-1(表示不存在,查找失败)。 例如 0 1 2 4 5 6 7 可能成为 4 5 6 7 0 1 2. 思路分析: 用二分搜索来找到转折点,也就是最小数的位置。对二分搜索要稍作修改,当a[left]<=a[mid],可以肯定a[ 阅读全文

posted @ 2016-02-09 13:33 鼬与轮回 阅读(178) 评论(0) 推荐(0) 编辑

2016年1月19日 #

Substring with Concatenation of All Words

摘要: 原题链接You are given a string,s, and a list of words,words, that are all of the same length. Find all starting indices of substring(s) insthat is a conca... 阅读全文

posted @ 2016-01-19 00:57 鼬与轮回 阅读(210) 评论(0) 推荐(0) 编辑

2016年1月4日 #

Subsets 子集系列问题 leetcode

摘要: 子集系列问题:Coding 问题中有时会出现这样的问题:给定一个集合,求出这个集合所有的子集(所谓子集,就是包含原集合中的一部分元素的集合)。或者求出满足一定要求的子集,比如子集中元素总和为定值,子集元素个数为定值等等。我把它们归类为子集系列问题。leetcode上原题链接:思路分析:思路一可以用递... 阅读全文

posted @ 2016-01-04 00:49 鼬与轮回 阅读(727) 评论(0) 推荐(0) 编辑

2015年12月27日 #

Sudoku Solver Backtracking

摘要: 该博客好好分析Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there wil... 阅读全文

posted @ 2015-12-27 23:38 鼬与轮回 阅读(258) 评论(0) 推荐(0) 编辑

Valid Sudoku leetcode

摘要: 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 ... 阅读全文

posted @ 2015-12-27 21:04 鼬与轮回 阅读(187) 评论(0) 推荐(0) 编辑

《如何求解问题》-现代启发式方法

摘要: 心情急躁,就无法获得很多人称之为艺术的东西;求解的艺术不在于你能够随时随地的给出一个堪称典范的解法; 即使是学习了一大堆的知识,我们也没有记住多少;因为大脑有一个或者是缺陷,也或者正是其美妙的地方——他并不记住所有的一切。似乎用这一点来划分它与电脑的区别。知识没有获得,学习只是将我们自... 阅读全文

posted @ 2015-12-27 14:15 鼬与轮回 阅读(340) 评论(0) 推荐(0) 编辑

2015年12月26日 #

Next Permutation

摘要: 原题地址:https://leetcode.com/submissions/detail/48922153/ 所谓一个排列的下一个排列的意思就是 这一个排列与下一个排列之间没有其他的排列。这就要求这一个排列与下一个排列有尽可能长的共同前缀,也即变化限制在尽可能短的后缀上。这句话的意思我一直没弄明白! 阅读全文

posted @ 2015-12-26 13:45 鼬与轮回 阅读(259) 评论(0) 推荐(0) 编辑

2015年12月25日 #

Excel Sheet Column Title

摘要: Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 ->... 阅读全文

posted @ 2015-12-25 19:08 鼬与轮回 阅读(218) 评论(0) 推荐(0) 编辑

Remove Linked List Elements

摘要: Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --... 阅读全文

posted @ 2015-12-25 13:28 鼬与轮回 阅读(116) 评论(0) 推荐(0) 编辑

2015年12月24日 #

Substring with Concatenation of All Words

摘要: You are given a string,s, and a list of words,words, that are all of the same length. Find all starting indices of substring(s) insthat is a concatena... 阅读全文

posted @ 2015-12-24 14:53 鼬与轮回 阅读(189) 评论(0) 推荐(0) 编辑

2015年12月22日 #

Divide Two Integers leetcode

摘要: 题目:Divide Two IntegersDivide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.看讨论区大神的思路:In this ... 阅读全文

posted @ 2015-12-22 00:42 鼬与轮回 阅读(188) 评论(0) 推荐(0) 编辑

2015年10月21日 #

Implement strStr() leetcode

摘要: Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The si... 阅读全文

posted @ 2015-10-21 00:08 鼬与轮回 阅读(138) 评论(0) 推荐(0) 编辑

2015年10月17日 #

Longest Valid Parentheses 每每一看到自己的这段没通过的辛酸代码

摘要: Longest Valid ParenthesesMy SubmissionsQuestionSolutionTotal Accepted:47520Total Submissions:222865Difficulty:HardGiven a string containing just the c... 阅读全文

posted @ 2015-10-17 00:04 鼬与轮回 阅读(212) 评论(1) 推荐(0) 编辑