
Algorithm
文章平均质量分 60
sherine
这个作者很懒,什么都没留下…
展开
-
KMP算法
前言:解 题目 Leetcode 28 Implement strStr()时,查阅和整理了关于KMP算法的资料。 The complexity of the getnext() algorithm is O(k), where k is the length of patterns(模式串/needles)。 next数组的构建的时间复杂度是O(k) The search port原创 2016-05-11 20:22:13 · 3267 阅读 · 0 评论 -
(Leetcode)400. Nth Digit
400. Nth Digit Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … Note: n is positive and will fit within the range of a 32-bit signed integer (n原创 2017-09-14 21:46:51 · 324 阅读 · 0 评论 -
(Leetcode)Longest Increasing Subsequence——dp,bisearch
300. Longest Increasing Subsequence 题目 Given an unsorted array of integers, find the length of longest increasing subsequence.For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing原创 2017-03-31 23:17:46 · 457 阅读 · 0 评论 -
原码, 反码, 补码 详解
为看懂Leetcode的260. Single Number III的位运算的解法,专门去补习了一下原码、补码的相关知识。260. Single Number IIIGiven an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exac原创 2016-12-28 20:29:29 · 473 阅读 · 0 评论 -
(Leetcode)238. Product of Array Except Self
238. Product of Array Except Self Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it原创 2016-12-27 13:43:10 · 285 阅读 · 0 评论 -
Majority Vote Alogrithm 多数投票算法
当一个序列中存在一个占大多数的的元素的时候(超过50%),该算法可以在O(1)空间和O(n)时间内找出这个元素。Tips: ⌊ 59/60⌋ = 0, floor(),向下取整 Majority Element Given an array of size n, find the majority element. The majority element is the element th原创 2016-12-25 22:44:44 · 1071 阅读 · 1 评论 -
(Leetcode)Ugly Number
264. Ugly Number IIWrite a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence o原创 2017-01-03 11:22:46 · 409 阅读 · 0 评论 -
(Leetcode)判断一个图是否是可以拓扑排序的——使用Queue
207. Course Schedule 拓扑排序 Topological Order 对一个有向无环图(Directed Acyclic Graph简称DAG)G进行拓扑排序,是将G中所有顶点排成一个线性序列,使得图中任意一对顶点u和v,若边(u,v)∈E(G),则u在线性序列中出现在v之前。 通常,这样的线性序列称为满足拓扑次序(Topological Orde原创 2016-12-04 23:30:14 · 1636 阅读 · 0 评论 -
Trie(prefix tree,前缀树,字典树)
Trie(Prefix tree, 前缀树,字典树)简介在计算机科学中,trie,又称前缀树或字典树,是一种有序树,用于保存关联数组,其中的键通常是字符串。与二叉查找树不同,键不是直接保存在节点中,而是由节点在树中的位置决定。一个节点的所有子孙都有相同的前缀,也就是这个节点对应的字符串,而根节点对应空字符串。一般情况下,不是所有的节点都有对应的值,只有叶子节点和部分内部节点所对应的键才有相关的值。原创 2016-12-07 16:04:33 · 1172 阅读 · 0 评论 -
(LeetCode)179. Largest Number——巧用string.compreTo和泛型接口Comparator
179. Largest NumberGiven a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result原创 2016-11-16 22:38:15 · 359 阅读 · 0 评论 -
(Leetcode)链表的slow,fast指针使用
141. Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Code-Java/** * Definition for singly-linked list. * class ListNode原创 2016-11-06 15:51:03 · 1029 阅读 · 0 评论 -
(Leetcode)利用preorder-inorder/postorder-inorder构建二叉树
105. Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, construct the binary tree.分析 根据preorder获得root节点(preorder第1个node),通过root在inorder中的位原创 2016-10-22 01:53:07 · 1171 阅读 · 0 评论 -
(Leetcode)92. Reverse Linked List II ——反转单链表
92. Reverse Linked List IIReverse 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,return 1->4->3->2->5->NULL.Note:Given m, n原创 2016-10-09 20:52:18 · 334 阅读 · 0 评论 -
(Leetcode)backtracking回溯法 题目汇总
回溯法 Backtracking Backtracking比较形象来说可以用走迷宫做例子,大多人类一般就是使用回溯法,当走到一条死路,就往回退到前一个岔路,尝试另外一条,直到走出。简介中文称做「**回溯法**」,穷举多维度数据的方法,可以想作是多维度的**穷举搜索(Exhaustive Search)**。大意是:把多维度数据看做是是一个多维向量(solution vector),然后运用递原创 2016-09-02 17:03:07 · 1395 阅读 · 1 评论 -
(Leetcode)37. Sudoku Solver
回溯法(Backtracking)求数独的解回溯法 Backtracking 深度优先搜索 策略 遍历空间树,找到一个结点。如果符合解的要求,则继续向下探索;如果不符合解的要求,则退回其父节点。 比较形象来说可以用走迷宫做例子,大多人类一般就是使用回溯法,当走到一条死路,就往回退到前一个岔路,尝试另外一条,直到走出。Problem 37. Sudoku Solver:Write原创 2016-06-29 22:11:56 · 269 阅读 · 0 评论