
LeetCode
文章平均质量分 72
FightForProgrammer
这个作者很懒,什么都没留下…
展开
-
LeetCode Word Break
LeetCode Word BreakGiven a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "l原创 2015-06-10 09:57:42 · 766 阅读 · 0 评论 -
LeetCode : Partition List
Partition List Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of原创 2015-03-31 09:29:09 · 629 阅读 · 0 评论 -
LeetCode:Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the t原创 2015-03-29 08:58:14 · 993 阅读 · 0 评论 -
LeetCode Repeated DNA Sequences
LeetCode Repeated DNA SequencesAll DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repe原创 2015-03-10 19:45:55 · 774 阅读 · 0 评论 -
LeetCode Min Stack
LeetCode Min StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of原创 2015-03-21 10:33:28 · 725 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
LeetCode :Binary Tree Maximum Path SumGiven a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree,原创 2015-03-27 15:21:35 · 916 阅读 · 0 评论 -
LeetCode Rotate Array
LeetCode Rotate ArrayRotate Array Total Accepted: 5488 Total Submissions: 29811 My Submissions Question Solution Rotate an array of n elements to the right by k steps.For example, with n = 7原创 2015-03-03 15:16:48 · 1561 阅读 · 0 评论 -
Rotate Image
LeetCode Rotate ImageYou are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?关键地方在于就地。而不用新的内存。原创 2015-01-25 20:33:04 · 643 阅读 · 0 评论 -
LeetCode Triangle
LeetCode TriangleGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[原创 2015-01-04 16:10:53 · 631 阅读 · 0 评论 -
Unique Binary Search Trees
LeetCode Unique Binary Search Trees I IIⅠ第一题主要用到了数学推导的方法。令数组arr[i]表示i个节点时BST的数目。则arr[0]=arr[1]=1,arr[2] = 2.对于已知的arr[0...n]求arr[n+1],此n+1个节点中有个是根节点,令它的左子树个数L(n),右子数节点个数R(n),则左子树有arr[L(n)]中原创 2015-01-21 21:43:28 · 529 阅读 · 0 评论 -
LeetCode:Distinct Subsequences
Distinct SubsequencesGiven a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string b原创 2015-04-01 18:51:34 · 576 阅读 · 0 评论 -
LeetCode House Robber
LeetCode House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of原创 2015-05-10 17:08:03 · 797 阅读 · 0 评论 -
LeetCode Maximal Square
LeetCode Maximal SquareGiven a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01原创 2015-06-05 15:06:40 · 614 阅读 · 0 评论 -
LeetCode Implement Trie (Prefix Tree)
LeetCode Implement Trie (Prefix Tree)Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.题目要求是实现字典原创 2015-05-19 10:30:15 · 702 阅读 · 0 评论 -
Word Ladder
Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a timeEach int原创 2015-06-21 17:21:59 · 698 阅读 · 0 评论 -
LeetCode Contains Duplicate II Contains Duplicate III
Contains Duplicate II Contains Duplicate III一、Contains Duplicate II Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the原创 2015-06-02 15:27:53 · 756 阅读 · 0 评论 -
LeetCode Course Schedule
LeetCode Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take co原创 2015-05-31 10:41:54 · 1158 阅读 · 0 评论 -
LeetCode Word Search II
LeetCode Word Search IIGiven a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "原创 2015-05-28 14:37:06 · 1200 阅读 · 0 评论 -
LeetCode Add and Search Word - Data structure design
Add and Search Word - Data structure design Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word o原创 2015-05-21 14:59:53 · 749 阅读 · 0 评论 -
LeetCode Minimum Size Subarray Sum
LeetCode Minimum Size Subarray SumGiven an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 inste原创 2015-05-16 22:03:16 · 899 阅读 · 0 评论 -
LeetCode LRU Cache
LeetCode LRU CacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be原创 2015-05-15 15:52:09 · 738 阅读 · 0 评论 -
Gray Code
LeetCode Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code原创 2015-01-22 13:55:01 · 708 阅读 · 0 评论 -
Best Time to Buy and Sell Stock I II III
Best Time to Buy and Sell Stock I II IIII对于第一题,本质意义是求出数组中某两个元素(day[i],day[i])的最大差值。但是,要求j>iint maxProfit(vector &prices) { if(prices.size() ==0) return 0;原创 2015-01-19 23:44:10 · 733 阅读 · 0 评论 -
LeetCode Recover Binary Search Tree
LeetCode Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is原创 2015-01-01 23:58:05 · 622 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array
Find Minimum in Rotated Sorted Array原创 2014-11-05 13:08:39 · 522 阅读 · 0 评论 -
LeetCode Gas Station
LeetCode Gas StationGas Station There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it cost原创 2014-11-27 23:22:40 · 774 阅读 · 0 评论 -
LeetCode:Reorder List
LeetCode:Reorder ListGiven a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1原创 2014-11-01 10:05:50 · 594 阅读 · 0 评论 -
LeetCode:Sort List
LeetCode:Sort ListSort a linked list in O(n log n) time using constant space complexity.原创 2014-10-31 00:28:40 · 588 阅读 · 0 评论 -
Longest Consecutive Sequence
LeetCode Longest Consecutive Sequence原创 2014-11-13 23:12:33 · 640 阅读 · 0 评论 -
LeetCode Insertion Sort List
LeetCode : Insertion Sort ListInsertion Sort List Sort a linked list using insertion sort.原创 2014-10-29 01:05:37 · 722 阅读 · 0 评论 -
LeetCode Count and Say
LeetCode:Count and SayThe 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 read off as "two原创 2014-10-26 23:51:07 · 556 阅读 · 0 评论 -
LeetCode--isSameTree
LeetCode--isSameTree原创 2014-10-25 22:50:21 · 996 阅读 · 0 评论 -
Sum Root to Leaf Numbers
LeetCode Sum Root to Leaf Numbers原创 2014-11-09 20:39:32 · 592 阅读 · 0 评论 -
Maximum Product Subarray
LeetCode Maximum Product Subarray原创 2014-11-06 13:09:42 · 597 阅读 · 0 评论 -
LeetCode Convert Sorted List to Binary Search Tree
LeetCode Convert Sorted List to Binary Search TreeConvert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in ascending order, convert it to a heigh原创 2014-12-17 20:02:06 · 717 阅读 · 0 评论 -
LeetCode Populating Next Right Pointers in Each Node
LeetCode Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }原创 2014-12-14 13:57:04 · 637 阅读 · 0 评论 -
LeetCode Flatten Binary Tree to Linked List
LeetCode Flatten Binary Tree to Linked ListGiven a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6原创 2014-12-13 23:59:28 · 704 阅读 · 0 评论 -
LeetCode Longest Palindromic Substring
LeetCode Longest Palindromic SubstringGiven 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 pa原创 2014-12-30 00:17:29 · 697 阅读 · 0 评论 -
LeetCode Permutations
LeetCode PermutationsGiven 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],原创 2014-12-12 21:27:27 · 588 阅读 · 0 评论 -
LeetCode N-Queens
LeetCode N-QueensThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions t原创 2014-12-11 13:01:50 · 577 阅读 · 0 评论