E-COM-NET
首页
在线工具
Layui镜像站
SUI文档
联系我们
推荐频道
Java
PHP
C++
C
C#
Python
Ruby
go语言
Scala
Servlet
Vue
MySQL
NoSQL
Redis
CSS
Oracle
SQL Server
DB2
HBase
Http
HTML5
Spring
Ajax
Jquery
JavaScript
Json
XML
NodeJs
mybatis
Hibernate
算法
设计模式
shell
数据结构
大数据
JS
消息中间件
正则表达式
Tomcat
SQL
Nginx
Shiro
Maven
Linux
Leetcode笔记
leetcode笔记
:Pascal's Triangle II
一.题目描述Givenanindexk,returnthekthrowofthePascal’striangle.Forexample,givenk=3,Return[1,3,3,1].Note:CouldyouoptimizeyouralgorithmtouseonlyO(k)extraspace?二.题目分析关于帕斯卡三角形的定义,可参考:http://baike.baidu.com/link
liyuefeilong
·
2016-01-11 19:00
LeetCode
Algorithm
C++
vector
pascal
leetcode笔记
:Pascal's Triangle
一.题目描述GivennumRows,generatethefirstnumRowsofPascal’striangle.Forexample,givennumRows=5,Return:[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]二.题目分析关于帕斯卡三角形的定义,可参考:http://baike.baidu.com/link?url=qk_-u
liyuefeilong
·
2016-01-11 01:00
LeetCode
Algorithm
C++
vector
pascal
leetcode笔记
:Product of Array Except Self
一.题目描述Givenanarrayofnintegerswheren>1,nums,returnanarrayoutputsuchthatoutput[i]isequaltotheproductofalltheelementsofnumsexceptnums[i].SolveitwithoutdivisionandinO(n).Forexample,given[1,2,3,4],return[2
liyuefeilong
·
2016-01-10 19:00
LeetCode
Algorithm
C++
算法
array
leetcode笔记
:Ugly Number II
一.题目描述Writeaprogramtofindthen-thuglynumber.Uglynumbersarepositivenumberswhoseprimefactorsonlyinclude2,3,5.Forexample,1,2,3,4,5,6,8,9,10,12isthesequenceofthefirst10uglynumbers.Notethat1istypicallytreat
liyuefeilong
·
2016-01-10 18:00
LeetCode
Algorithm
C++
算法
丑数
leetcode笔记
:Ugly Number
一.题目描述Writeaprogramtocheckwhetheragivennumberisanuglynumber.Uglynumbersarepositivenumberswhoseprimefactorsonlyinclude2,3,5.Forexample,6,8areuglywhile14isnotuglysinceitincludesanotherprimefactor7.Notet
liyuefeilong
·
2016-01-10 18:00
LeetCode
Algorithm
C++
算法
丑数
leetcode笔记
:Power of Three
一.题目描述Givenaninteger,writeafunctiontodetermineifitisapowerofthree.Followup:Couldyoudoitwithoutusinganyloop/recursion?二.题目分析题目的大意很简单,给出一个整数,判断这个整数是不是3的整数次幂。下面提示尽量不适用循环和递归来实现,因此这里给出两种实现方法,其中第一种循环方式的耗时更少
liyuefeilong
·
2016-01-10 17:00
LeetCode
Algorithm
C++
power
recursion
leetcode笔记
语言:java第二题Youaregiventwolinkedlistsrepresentingtwonon-negativenumbers.Thedigitsarestoredinreverseorderandeachoftheirnodescontainasingledigit.Addthetwonumbersandreturnitasalinkedlist.Input: (2->4->3)+(
landai2011
·
2016-01-10 15:00
java
LeetCode
lists
linked
leetcode笔记
:Validate Binary Search Tree
一.题目描述Givenabinarytree,determineifitisavalidbinarysearchtree(BST).AssumeaBSTisdefinedasfollows:Theleftsubtreeofanodecontainsonlynodeswithkeyslessthanthenode’skey.Therightsubtreeofanodecontainsonlynode
liyuefeilong
·
2016-01-07 23:00
LeetCode
C++
算法
tree
BST
leetcode笔记
:Leetcode Letter Combinations of a Phone Number
一.题目描述Givenadigitstring,returnallpossiblelettercombinationsthatthenumbercouldrepresent.Amappingofdigittoletters(justlikeonthetelephonebuttons)isgivenbelow.Input:Digitstring"23" Output:["ad","ae","af",
liyuefeilong
·
2016-01-05 22:00
LeetCode
C++
算法
String
DFS
leetcode笔记
:Convert Sorted List to Binary Search Tree
一.题目描述Givenasinglylinkedlistwhereelementsaresortedinascendingorder,convertittoaheightbalancedBST.二.题目分析这道题只要将列表转化为一个数组,就可以使用和题目ConvertSortedArraytoBinarySearchTree一样的方法来进行,这种方法的时间复杂度为O(n),空间复杂度为O(n^2)
liyuefeilong
·
2016-01-04 00:00
LeetCode
C++
list
array
BST
leetcode笔记
:Convert Sorted Array to Binary Search Tree
一.题目描述Givenanarraywhereelementsaresortedinascendingorder,convertittoaheightbalancedBST.二.题目分析将二叉查找树进行中序遍历,就可以得到一个升序排序的数组,因此,一个已经排序的数组可以看做一个中序遍历得到的数组,要得到一个高度平衡的二叉查找树,可以使得左右子树的节点数尽可能相等。因此,可以采用二分法将数组分为两个
liyuefeilong
·
2016-01-02 21:00
LeetCode
Algorithm
C++
vector
BST
leetcode笔记
:Palindrome Number
一.题目描述Determinewhetheranintegerisapalindrome.Dothiswithoutextraspace.Somehints:Couldnegativeintegersbepalindromes?(ie,-1)Ifyouarethinkingofconvertingtheintegertostring,notetherestrictionofusingextrasp
liyuefeilong
·
2015-12-31 23:00
LeetCode
Algorithm
算法
String
palindrome
leetcode笔记
:Reverse Integer
一.题目描述Reversedigitsofaninteger.Example1:x=123,return321Example2:x=-123,return-321二.题目分析反转一个整数,若为负数,则负号不变,然后反转负数。该题题设虽然简单,但隐藏一些陷阱,如反转后数字的溢出问题、低位为0时反转到高位时又怎么处理。这种题目目的不是为了考察某种算法,而是考察对各种边界条件是否考虑周全。这里的代码只是
liyuefeilong
·
2015-12-31 23:00
LeetCode
Algorithm
C++
算法
reverse
leetcode笔记
:Pow(x, n)
一.题目描述Implementpow(x,n).二.题目分析实现pow(x,n),即求x的n次幂。最容易想到的方法就是用递归直接求n个x的乘积,这里需要根据n的值,判断结果是正数还是负数,这种方法的时间复杂度为O(n)。更加快捷的方法是,使用分治法,对于x^n,有一下公式:x^n=x^(n/2)*x^(n/2)*x^(n%2)使用这种方法的时间复杂度为O(logn)。三.示例代码#include
liyuefeilong
·
2015-12-31 23:00
LeetCode
Algorithm
C++
power
divide
leetcode笔记
:Sqrt(x)
一.题目描述Implementintsqrt(intx).Computeandreturnthesquarerootofx.二.题目分析该题要求实现求根公式,该题还算是比较简单的,因为只需返回最接近的整数,直接二分法即可。在实现的过程中还是有一些细节的,比如判断条件:x/mid>mid而不能是x>mid*mid,因为mid*mid会导致溢出。三.示例代码#include usingnamespa
liyuefeilong
·
2015-12-31 22:00
LeetCode
Algorithm
算法
sqrt
divide
leetcode笔记
:Subsets II
一.题目描述Givenacollectionofintegersthatmightcontainduplicates,nums,returnallpossiblesubsets.Note:Elementsinasubsetmustbeinnon-descendingorder.Thesolutionsetmustnotcontainduplicatesubsets.Forexample,Ifnum
liyuefeilong
·
2015-12-29 23:00
LeetCode
C++
vector
DFS
Subsets
leetcode笔记
:Nim Game
一.题目描述YouareplayingthefollowingNimGamewithyourfriend:Thereisaheapofstonesonthetable,eachtimeoneofyoutaketurnstoremove1to3stones.Theonewhoremovesthelaststonewillbethewinner.Youwilltakethefirstturntorem
liyuefeilong
·
2015-12-29 00:00
LeetCode
Algorithm
C++
算法
Nim
leetcode笔记
:Subsets
一.题目描述Givenasetofdistinctintegers,nums,returnallpossiblesubsets.Note:Elementsinasubsetmustbeinnon-descendingorder.Thesolutionsetmustnotcontainduplicatesubsets.Forexample,Ifnums=[1,2,3],asolutionis:[ [
liyuefeilong
·
2015-12-28 22:00
LeetCode
位运算
C++
DFS
Subsets
leetcode笔记
:Same Tree
一.题目描述Giventwobinarytrees,writeafunctiontocheckiftheyareequalornot.Twobinarytreesareconsideredequaliftheyarestructurallyidenticalandthenodeshavethesamevalue.二.题目分析题目的意思很简单,判断两棵树是否相同,递归,对两棵树的结点进行比较即可。三
liyuefeilong
·
2015-12-27 11:00
LeetCode
C++
递归
tree
binary
leetcode笔记
:Partition List
一.题目描述Givenalinkedlistandavaluex,partitionitsuchthatallnodeslessthanxcomebeforenodesgreaterthanorequaltox.Youshouldpreservetheoriginalrelativeorderofthenodesineachofthetwopartitions.Forexample,Given1-
liyuefeilong
·
2015-12-27 01:00
LeetCode
C++
算法
list
链表
leetcode笔记
:Wildcard Matching
一.题目描述Implementwildcardpatternmatchingwithsupportfor‘?’and‘*’.‘?’Matchesanysinglecharacter.‘*’Matchesanysequenceofcharacters(includingtheemptysequence).Thematchingshouldcovertheentireinputstring(notpa
liyuefeilong
·
2015-12-26 18:00
LeetCode
Algorithm
String
character
wildcard
leetcode笔记
:Search Insert Position
一.题目描述Givenasortedarrayandatargetvalue,returntheindexifthetargetisfound.Ifnot,returntheindexwhereitwouldbeifitwereinsertedinorder.Youmayassumenoduplicatesinthearray.Herearefewexamples.[1,3,5,6],5→2 [1
liyuefeilong
·
2015-12-25 20:00
LeetCode
C++
算法
二分查找
sort
leetcode笔记
:First Bad Version
一.题目描述Youareaproductmanagerandcurrentlyleadingateamtodevelopanewproduct.Unfortunately,thelatestversionofyourproductfailsthequalitycheck.Sinceeachversionisdevelopedbasedonthepreviousversion,alltheversi
liyuefeilong
·
2015-12-25 17:00
LeetCode
C++
算法
二分查找
leetcode笔记
:Search for a Range
一.题目描述Givenasortedarrayofintegers,findthestartingandendingpositionofagiventargetvalue.Youralgorithm’sruntimecomplexitymustbeintheorderofO(logn).Ifthetargetisnotfoundinthearray,return[-1,-1].Forexample
liyuefeilong
·
2015-12-25 16:00
LeetCode
C++
二分查找
算法
vector
leetcode笔记
:Sort Colors
一.题目描述Givenanarraywithnobjectscoloredred,whiteorblue,sortthemsothatobjectsofthesamecolorareadjacent,withthecolorsintheorderred,whiteandblue.Here,wewillusetheintegers0,1,and2torepresentthecolorred,whit
liyuefeilong
·
2015-12-24 23:00
LeetCode
C++
排序
算法
sort
leetcode笔记
:First Missing Positive
一.题目描述Givenanunsortedintegerarray,findthefirstmissingpositiveinteger.Forexample,Given[1,2,0]return3,and[3,4,-1,1]return2.YouralgorithmshouldruninO(n)timeandusesconstantspace.二.题目分析该题的大意是给定一个未排序的数组,该数组
liyuefeilong
·
2015-12-24 01:00
Algorithm
LeetCode
C++
vector
positive
leetcode笔记
:Longest Substring Without Repeating Characters
一.题目描述Givenastring,findthelengthofthelongestsubstringwithoutrepeatingcharacters.Forexample,thelongestsubstringwithoutrepeatinglettersfor“abcabcbb”is“abc”,whichthelengthis3.For“bbbbb”thelongestsubstrin
liyuefeilong
·
2015-12-16 23:00
LeetCode
C++
String
char
substring
leetcode笔记
:Jump Game II
一.题目描述Givenanarrayofnon-negativeintegers,youareinitiallypositionedatthefirstindexofthearray.Eachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Yourgoalistoreachthelastindexintheminimum
liyuefeilong
·
2015-12-16 00:00
LeetCode
Algorithm
C++
贪心
greedy
leetcode笔记
:Jump Game
一.题目描述Givenanarrayofnon-negativeintegers,youareinitiallypositionedatthefirstindexofthearray.Eachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Determineifyouareabletoreachthelastindex.
liyuefeilong
·
2015-12-15 23:00
Algorithm
LeetCode
C++
贪心
greedy
leetcode笔记
:Spiral Matrix
一.题目描述Givenamatrixofmnelements(mrows,ncolumns),returnallelementsofthematrixinspiralorder.Forexample,Giventhefollowingmatrix:[ [1,2,3], [4,5,6], [7,8,9] ]Youshouldreturn[1,2,3,6,9,8,7,4,5].二.题目分析题意:给定
liyuefeilong
·
2015-12-12 21:00
LeetCode
Algorithm
C++
vector
Matrix
leetcode笔记
:Word Ladder
一.题目描述Giventwowords(startandend),andadictionary,findthelengthofshortesttransformationsequencefromstarttoend,suchthat:•Onlyonelettercanbechangedatatime•EachintermediatewordmustexistinthedictionaryForex
liyuefeilong
·
2015-12-10 23:00
LeetCode
Algorithm
C++
String
bfs
leetcode笔记
:Word Search II
一.题目描述Givena2Dboardandalistofwordsfromthedictionary,findallwordsintheboard.Eachwordmustbeconstructedfromlettersofsequentiallyadjacentcell,where“adjacent”cellsarethosehorizontallyorverticallyneighborin
liyuefeilong
·
2015-12-10 00:00
LeetCode
Algorithm
C++
String
trie
leetcode笔记
:Word Search
一.题目描述Givena2Dboardandaword,findifthewordexistsinthegrid.Thewordcanbeconstructedfromlettersofsequentiallyadjacentcell,where“adjacent”cellsarethosehorizontallyorverticallyneighbouring.Thesamelettercell
liyuefeilong
·
2015-12-08 23:00
LeetCode
C++
String
递归
DFS
leetcode笔记
:Longest Consecutive Sequence
一.题目描述Givenanunsortedarrayofintegers,findthelengthofthelongestconsecutiveelementssequence.Forexample,Given[100,4,200,1,3,2],Thelongestconsecutiveelementssequenceis[1,2,3,4].Returnitslength:4.Youralgor
liyuefeilong
·
2015-12-03 23:00
LeetCode
Algorithm
C++
算法
hash
leetcode笔记
:Construct Binary Tree from Inorder and Postorder Traversal
一.题目描述Giveninorderandpostordertraversalofatree,constructthebinarytree.Note:Youmayassumethatduplicatesdonotexistinthetree.二.题目分析这道题和ConstructBinaryTreefromPreorderandInorderTraversal类似,都是考察基本概念的,后序遍历是先
liyuefeilong
·
2015-12-01 00:00
LeetCode
C++
二叉树
遍历
traversal
leetcode笔记
:Construct Binary Tree from Preorder and Inorder Traversal
一.题目描述Givenpreorderandinordertraversalofatree,constructthebinarytree.Note:Youmayassumethatduplicatesdonotexistinthetree.二.题目分析这道题考察了先序和中序遍历,先序是先访问根节点,然后访问左子树,最后访问右子树;中序遍历是先遍历左子树,然后访问根节点,最后访问右子树。做法都是先根
liyuefeilong
·
2015-11-30 23:00
LeetCode
C++
二叉树
遍历
traversal
leetcode笔记
:Combination Sum III
一.题目描述Findallpossiblecombinationsofknumbersthatadduptoanumbern,giventhatonlynumbersfrom1to9canbeusedandeachcombinationshouldbeauniquesetofnumbers.Ensurethatnumberswithinthesetaresortedinascendingorder
liyuefeilong
·
2015-11-27 22:00
LeetCode
Algorithm
C++
vector
DFS
leetcode笔记
:Combination Sum II
一.题目描述Givenasetofcandidatenumbers(C)andatargetnumber(T),findalluniquecombinationsinCwherethecandidatenumberssumstoT.ThesamerepeatednumbermaybechosenfromConcenumberoftimes.Note:•Allnumbers(includingtar
liyuefeilong
·
2015-11-27 21:00
LeetCode
Algorithm
C++
vector
DFS
leetcode笔记
:Combination Sum
一.题目描述Givenasetofcandidatenumbers(C)andatargetnumber(T),findalluniquecombinationsinCwherethecandidatenumberssumstoT.ThesamerepeatednumbermaybechosenfromCunlimitednumberoftimes.Note:•Allnumbers(includi
liyuefeilong
·
2015-11-25 23:00
Algorithm
LeetCode
C++
算法
DFS
leetcode笔记
:Restore IP Addresses
一.题目描述Givenastringcontainingonlydigits,restoreitbyreturningallpossiblevalidIPaddresscombinations.Forexample:Given”25525511135”,return[”255.255.11.135”,”255.255.111.35”].(Orderdoesnotmatter)二.题目分析题目的大意
liyuefeilong
·
2015-11-22 00:00
LeetCode
算法
String
IP
DFS
leetcode笔记
:N-Queens II
一.题目描述FollowupforN-Queensproblem.Now,insteadoutputtingboardconfigurations,returnthetotalnumberofdistinctsolutions.二.题目分析题目与N-Queens的方法基本相同,但比后者更为简单,因为题目只要求输出合适解的个数,不需要打印所有解,代码要比上一题简化很多。设一个全局变量,每遍历到底部一
liyuefeilong
·
2015-11-21 23:00
LeetCode
C++
DFS
深搜
n-queen
leetcode笔记
:N-Queens
一.题目描述Then-queenspuzzleistheproblemofplacingnqueensonannnchessboardsuchthatnotwoqueensattackeachother.Givenanintegern,returnalldistinctsolutionstothen-queenspuzzle.Eachsolutioncontainsadistinctboardc
liyuefeilong
·
2015-11-17 23:00
LeetCode
C++
算法
DFS
nqueens
leetcode笔记
:Decode Ways
一.题目描述AmessagecontaininglettersfromA-Zisbeingencodedtonumbersusingthefollowingmapping:'A'->1 'B'->2 ... 'Z'->26Givenanencodedmessagecontainingdigits,determinethetotalnumberofwaystodecodeit.Forexample,
liyuefeilong
·
2015-11-13 23:00
LeetCode
C++
算法
dp
动态规划
leetcode笔记
:Best Time to Buy and Sell Stock IV
一.题目描述Sayyouhaveanarrayforwhichtheithelementisthepriceofagivenstockondayi.Designanalgorithmtofindthemaximumprofit.Youmaycompleteatmostktransactions.Note:Youmaynotengageinmultipletransactionsatthesamet
liyuefeilong
·
2015-11-12 20:00
LeetCode
C++
算法
dp
动态规划
leetcode笔记
:Best Time to Buy and Sell Stock III
一.题目描述Sayyouhaveanarrayforwhichthei-thelementisthepriceofagivenstockondayi.Designanalgorithmtofindthemaximumprofit.Youmaycompleteatmosttwotransactions.Note:Youmaynotengageinmultipletransactionsatthesa
liyuefeilong
·
2015-11-12 01:00
LeetCode
Algorithm
C++
算法
dp
leetcode笔记
:Best Time to Buy and Sell Stock II
一.题目描述Sayyouhaveanarrayforwhichthei-thelementisthepriceofagivenstockondayi.Designanalgorithmtofindthemaximumprofit.Youmaycompleteasmanytransactionsasyoulike(ie,buyoneandselloneshareofthestockmultiplet
liyuefeilong
·
2015-11-12 00:00
LeetCode
Algorithm
C++
算法
leetcode笔记
:Best Time to Buy and Sell Stock
一.题目描述Sayyouhaveanarrayforwhichthei-thelementisthepriceofagivenstockondayi.Ifyouwereonlypermittedtocompleteatmostonetransaction(ie,buyoneandselloneshareofthestock),designanalgorithmtofindthemaximumpro
liyuefeilong
·
2015-11-10 23:00
LeetCode
C++
dp
interview
leetcode笔记
:Edit Distance
一.题目描述Giventwowordsword1andword2,findtheminimumnumberofstepsrequiredtoconvertword1toword2.(eachoperationiscountedas1step.)Youhavethefollowing3operationspermittedonaword:InsertacharacterDeleteacharacte
liyuefeilong
·
2015-11-09 16:00
LeetCode
C++
dp
动态规划
distance
leetcode笔记
:Minimum Path Sum
一.题目描述Givenamngridfilledwithnon-negativenumbers,findapathfromtoplefttobottomrightwhichminimizesthesumofallnumbersalongitspath.Note:Youcanonlymoveeitherdownorrightatanypointintime二.题目分析题目的大意是,给定一个m*n的
liyuefeilong
·
2015-11-08 11:00
Algorithm
LeetCode
C++
dp
动态规划
leetcode笔记
:Interlaving String
一.题目描述Givens1;s2;s3,findwhethers3isformedbytheinterleavingofs1ands2.Forexample,Given:s1=“aabcc”,s2=“dbbca”,Whens3=“aadbbcbcac”,returntrue.Whens3=“aadbbbaccc”,returnfalse.二.题目分析此题可使用二维动态规划来解决,下表给出了直观的匹
liyuefeilong
·
2015-11-06 13:00
LeetCode
C++
String
dp
动态规划
上一页
10
11
12
13
14
15
16
17
下一页
按字母分类:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
其他