
Leetcode
文章平均质量分 60
sherine
这个作者很懒,什么都没留下…
展开
-
(Leetcode)22. Generate Parentheses
Problem: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: “((()))”, “(()())”, “(())(原创 2016-05-10 14:00:17 · 304 阅读 · 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)Unique Binary Search Trees I & II
96. Unique Binary Search TreesGiven n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3原创 2016-10-20 16:52:58 · 402 阅读 · 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)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 评论 -
Trie(prefix tree,前缀树,字典树)
Trie(Prefix tree, 前缀树,字典树)简介在计算机科学中,trie,又称前缀树或字典树,是一种有序树,用于保存关联数组,其中的键通常是字符串。与二叉查找树不同,键不是直接保存在节点中,而是由节点在树中的位置决定。一个节点的所有子孙都有相同的前缀,也就是这个节点对应的字符串,而根节点对应空字符串。一般情况下,不是所有的节点都有对应的值,只有叶子节点和部分内部节点所对应的键才有相关的值。原创 2016-12-07 16:04:33 · 1172 阅读 · 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 评论 -
(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 评论 -
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)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 评论 -
原码, 反码, 补码 详解
为看懂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)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)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)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 评论 -
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)7. Reverse Integer
(Leetcode)7. Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321这题的要点:int,Integer的范围: -2147483648 ~ 2147483647 一些边界值的考量,x=0,x=-2147483原创 2016-04-19 16:52:53 · 316 阅读 · 0 评论 -
(Leetcode)5. Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 寻找字符串S的最长回文子串回文串:类似abc原创 2016-05-04 18:36:34 · 301 阅读 · 0 评论 -
(Leetcode)11. Container With Most Water
题目: Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find t原创 2016-05-04 21:22:53 · 298 阅读 · 0 评论 -
(Leetcode)3. Longest Substring Without Repeating Characters
题目: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3原创 2016-03-25 22:53:07 · 282 阅读 · 0 评论 -
(Leetcode)37. Sudoku Solver
回溯法(Backtracking)求数独的解回溯法 Backtracking 深度优先搜索 策略 遍历空间树,找到一个结点。如果符合解的要求,则继续向下探索;如果不符合解的要求,则退回其父节点。 比较形象来说可以用走迷宫做例子,大多人类一般就是使用回溯法,当走到一条死路,就往回退到前一个岔路,尝试另外一条,直到走出。Problem 37. Sudoku Solver:Write原创 2016-06-29 22:11:56 · 269 阅读 · 0 评论 -
(Leetcode)39&40. Combination Sum--Using Backtracking
Problem39. Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be ch原创 2016-07-01 13:46:40 · 617 阅读 · 0 评论 -
(Leetcode)43. Multiply Strings
Problem43. Multiply Strings Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. C原创 2016-07-02 14:39:28 · 339 阅读 · 0 评论 -
(Leetcode)17. Letter Combinations of a Phone Number——使用LinkedList
题目:Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit stri原创 2016-05-08 00:02:31 · 455 阅读 · 0 评论 -
(Leetcode)46&47 Permutations--LinkedList and HashSet
Problem46.Permutations Given a collection of distinct numbers, return all possible permutations. 47. Permutations II Given a collection of numbers that might contain duplicates, return all possib原创 2016-07-06 17:13:55 · 292 阅读 · 0 评论 -
(Leetcode)49. Group Anagrams--Using HashMap
Problem49. Group Anagrams Given an array of strings, group anagrams together. For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return: [ [“ate”, “eat”,”tea”], [“原创 2016-07-07 17:43:54 · 297 阅读 · 0 评论 -
(Leetcode)31. Next Permutation
Problem 31. Next Permutation: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must原创 2016-06-22 21:21:48 · 342 阅读 · 0 评论 -
(Leetcode)371. Sum of Two Integers
371. Sum of Two Integers Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3.Solution思路题目要求不用+法进行加法运算,所以考虑原创 2016-08-28 21:27:47 · 350 阅读 · 0 评论