
算法
文章平均质量分 79
HAN_UESTC
这个作者很懒,什么都没留下…
展开
-
KMP算法学习笔记
参考http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html部分代码原作:http://www.cnblogs.com/Topless/archive/2011/10/16/2214450.htmljava代码:public class KPM { // ja原创 2016-02-10 22:04:28 · 500 阅读 · 0 评论 -
leetcode(198)(213) HouseRobber HouseRobber-II
原题链接:https://leetcode.com/problems/house-robber/https://leetcode.com/problems/house-robber-ii/第一题题意是一个贼要偷东西,有n户人家,如果偷相邻两家,就会触发警报。警报一响,警察来抓,逮走(做贼不容易啊)。问怎样在不触发警报而偷走最多的钱。第二题在第一题基础上有加了个收尾相连,即偷原创 2016-03-10 17:49:42 · 665 阅读 · 0 评论 -
leetcode(166) Fraction to Recurring Decimal
原题链接:https://leetcode.com/problems/fraction-to-recurring-decimal/这道题就是做除法,然后如果有无限循环的部分用括号表示比如1/3=0.3333...用0.(3)来表示,1234/9999=0.123412341234....用0.(1234)来表示循环判断用一个map来查看前面的一个数(或一串数)是否与后面的一个数(或一串原创 2016-03-10 15:30:04 · 539 阅读 · 0 评论 -
leetcode(121)(122)(123)(188) Best Time to Buy and Sell Stock I/II/III/IV JAVA代码
原题链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-Ihttps://leetcode.com/problems/best-time-to-buy-and-sell-stock-IIhttps://leetcode.com/problems/best-time-to-buy-and-sell-stock-原创 2016-03-08 10:51:47 · 842 阅读 · 0 评论 -
leetcode(92) Reverse Linked List II
原题链接:https://leetcode.com/problems/reverse-linked-list-ii/Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,原创 2016-02-20 21:10:59 · 619 阅读 · 0 评论 -
leetcode(304) Range Sum Query 2D - Immutable
题目链接:https://leetcode.com/problems/range-sum-query-2d-immutable/Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lowe原创 2016-02-20 19:33:22 · 689 阅读 · 0 评论 -
leetcode(207) Course Schedule即拓扑排序讲解
关于拓扑排序的知识点可以参看http://www.cnblogs.com/newpanderking/archive/2012/10/18/2729552.html及http://blog.youkuaiyun.com/midgard/article/details/4101025两篇写的很好,这里做一个粗略的讲解拓扑排序(topological-sort)是指由某个集合上的一个偏序得到该集合上的一个全序原创 2016-02-15 21:45:08 · 1696 阅读 · 0 评论 -
leetcode(284) Peeking Iterator
原题链接: https://leetcode.com/problems/peeking-iterator/Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operat原创 2016-02-15 15:52:21 · 471 阅读 · 0 评论 -
leetcode(153 154) FindMinimuminRotatedSortedArray与FindMinimuminRotatedSortedArray II
链接:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/两道题的唯一不同点就是有无元素重复用二分法解.重复情况下仅仅需要多写个else就好了第一题j原创 2016-02-13 18:10:02 · 485 阅读 · 0 评论 -
leetcode(2) Add Two Numbers
题目链接:https://leetcode.com/problems/add-two-numbers/You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a原创 2016-02-13 17:43:36 · 442 阅读 · 0 评论 -
leetcode(168) Excel Sheet Column Title
题目链接:https://leetcode.com/problems/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原创 2016-02-13 17:08:10 · 435 阅读 · 0 评论 -
leetcode(31) Next Permutation
https://leetcode.com/problems/next-permutation/Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not原创 2016-02-13 13:17:26 · 486 阅读 · 0 评论 -
Dijkstra算法
1.定义Dijkstra(迪杰斯特拉)算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径。主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止。Dijkstra算法是很有代表性的最短路径算法。注意该算法要求图中不存在负权边。下图是Dijkstra(迪杰斯特拉)算法的动态流程图Dijkstra算法其基本思想是,设置顶点集合S并不断地作贪心选择来扩充原创 2016-02-11 20:45:02 · 819 阅读 · 0 评论 -
leetcode(32) Longest Valid Parentheses
原题链接:https://leetcode.com/problems/longest-valid-parentheses/找到最多数量的()匹配思路:遇到左括号将左括号标号入栈,遇到右括号的情况下分两种情况:1.如果前面的左括号栈为空,说明前面已经没有左括号了,此时右括号无效,需要重新定位start数值2.如果前面的左括号栈不为空,这时要把这个左括号下标出栈,若为此时栈为空则max原创 2016-02-27 16:28:22 · 554 阅读 · 0 评论