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笔记
:104.Maximum Depth of Binary Tree
问题:Givenabinarytree,finditsmaximumdepth.Themaximumdepthisthenumberofnodesalongthelongestpathfromtherootnodedowntothefarthestleafnode.大意:给出一个二叉树,找到其最大的深度。最大深度是指从根节点到最远的叶子节点的最长距离的节点数。思路:要探索二叉树的深度,用递归比较方
Cloudox_
·
2016-03-26 14:00
LeetCode
二叉树
LeetCode笔记
:258.Add Digits
问题:Givenanon-negativeintegernum,repeatedlyaddallitsdigitsuntiltheresulthasonlyonedigit.Forexample:Givennum=38,theprocessislike:3+8=11,1+1=2.Since2hasonlyonedigit,returnit.Followup:Couldyoudoitwithouta
Cloudox_
·
2016-03-24 15:26
leetcode
c++
LeetCode
LeetCode笔记
LeetCode笔记
:258.Add Digits
问题:Givenanon-negativeintegernum,repeatedlyaddallitsdigitsuntiltheresulthasonlyonedigit.Forexample:Givennum=38,theprocessislike:3+8=11,1+1=2.Since2hasonlyonedigit,returnit.Followup:Couldyoudoitwithouta
Cloudox_
·
2016-03-24 15:00
LeetCode
C++
LeetCode笔记
:258.Add Digits
问题:Givenanon-negativeintegernum,repeatedlyaddallitsdigitsuntiltheresulthasonlyonedigit.Forexample:Givennum=38,theprocessislike:3+8=11,1+1=2.Since2hasonlyonedigit,returnit.Followup:Couldyoudoitwithouta
Cloudox_
·
2016-03-24 15:00
LeetCode
C++
LeetCode笔记
:292.Nim Game
问题:YouareplayingthefollowingNimGamewithyourfriend:Thereisaheapofstonesonthetable,eachtimeoneofyoutaketurnstoremove1to3stones.Theonewhoremovesthelaststonewillbethewinner.Youwilltakethefirstturntoremove
Cloudox_
·
2016-03-24 15:18
leetcode
c++
LeetCode
LeetCode笔记
LeetCode笔记
:292.Nim Game
问题:YouareplayingthefollowingNimGamewithyourfriend:Thereisaheapofstonesonthetable,eachtimeoneofyoutaketurnstoremove1to3stones.Theonewhoremovesthelaststonewillbethewinner.Youwilltakethefirstturntoremove
Cloudox_
·
2016-03-24 15:00
LeetCode
C++
LeetCode笔记
:292.Nim Game
问题:YouareplayingthefollowingNimGamewithyourfriend:Thereisaheapofstonesonthetable,eachtimeoneofyoutaketurnstoremove1to3stones.Theonewhoremovesthelaststonewillbethewinner.Youwilltakethefirstturntoremove
Cloudox_
·
2016-03-24 15:00
LeetCode
C++
leetcode笔记
:House Robber III
一.题目描述Thethiefhasfoundhimselfanewplaceforhisthieveryagain.Thereisonlyoneentrancetothisarea,calledthe“root.”Besidestheroot,eachhousehasoneandonlyoneparenthouse.Afteratour,thesmartthiefrealizedthat“allh
liyuefeilong
·
2016-03-14 20:00
LeetCode
C++
算法
dp
DFS
leetcode笔记
:Maximum Product of Word Lengths
一.题目描述Givenastringarraywords,findthemaximumvalueoflength(word[i])*length(word[j])wherethetwowordsdonotsharecommonletters.Youmayassumethateachwordwillcontainonlylowercaseletters.Ifnosuchtwowordsexist,r
liyuefeilong
·
2016-03-07 16:00
LeetCode
位运算
C++
算法
String
leetcode笔记
:Bitwise AND of Numbers Range
一.题目描述Givenarange[m,n]where0100->4 7:111再来两个例子:范围[6,8]:6:0110 7:0111->0000->0 8:1000范围[8,10]:8:1000 9:1001->1000->4 10:1010现在可以总结出规律了,对于范围[m,n],若n的最高有效位比m的最高有效位要高,则必然会出现像例子出现的情况,必然在范围内存在两个数,这两个数分别是对方的
liyuefeilong
·
2016-03-04 18:00
LeetCode
位运算
C++
bit
Bitwise
leetcode笔记
:Rectangle Area
一.题目描述Findthetotalareacoveredbytworectilinearrectanglesina2Dplane.Eachrectangleisdefinedbyitsbottomleftcornerandtoprightcornerasshowninthefigure.Assumethatthetotalareaisneverbeyondthemaximumpossibleva
liyuefeilong
·
2016-02-29 17:00
LeetCode
C++
算法
rectangle
2d
leetcode笔记
:Majority Element II
一.题目描述Givenanintegerarrayofsizen,findallelementsthatappearmorethan⌊n/3⌋times.ThealgorithmshouldruninlineartimeandinO(1)space.Hint:Howmanymajorityelementscoulditpossiblyhave?二.题目分析题目大意是,给定一个大小为n的整数数组,从
Herbert_Zero
·
2016-02-28 20:55
数据结构与算法
leetcode笔记
leetcode笔记
:Majority Element II
一.题目描述Givenanintegerarrayofsizen,findallelementsthatappearmorethan⌊n/3⌋times.ThealgorithmshouldruninlineartimeandinO(1)space.Hint:Howmanymajorityelementscoulditpossiblyhave?二.题目分析题目大意是,给定一个大小为n的整数数组,从
liyuefeilong
·
2016-02-28 20:00
LeetCode
C++
算法
vote
Moore
leetcode笔记
:Range Sum Query 2D - Immutable
一.题目描述Givena2Dmatrixmatrix,findthesumoftheelementsinsidetherectangledefinedbyitsupperleftcorner(row1,col1)andlowerrightcorner(row2,col2).Theaboverectangle(withtheredborder)isdefinedby(row1,col1)=(2,1)
liyuefeilong
·
2016-02-28 18:00
LeetCode
Algorithm
C++
算法
range
leetcode笔记
:Contains Duplicate III
一.题目描述Givenanarrayofintegers,findoutwhethertherearetwodistinctindicesiandjinthearraysuchthatthedifferencebetweennums[i]andnums[j]isatmosttandthedifferencebetweeniandjisatmostk.二.题目分析题目大意是,给定一个整数数组,判断其
liyuefeilong
·
2016-02-26 15:00
LeetCode
C++
算法
二叉树
BST
leetcode笔记
--Summary Ranges
题目:难度(Easy)Givenasortedintegerarraywithoutduplicates,returnthesummaryofitsranges.Forexample,given[0,1,2,4,5,7],return["0->2","4->5","7"].Tags:ArraySimilarProblems:(M)MissingRanges分析:i指向一个range片段的起始元素,
u010366748
·
2016-02-25 15:00
LeetCode
array
python
leetcode笔记
:Contains Duplicate II
一.题目描述Givenanarrayofintegersandanintegerk,findoutwhethertherearetwodistinctindicesiandjinthearraysuchthatnums[i]=nums[j]andthedifferencebetweeniandjisatmostk.二.题目分析题目的大意是,给定一个整数数组与一个整数k,当且仅当存在两个不同的下标i
liyuefeilong
·
2016-02-24 18:00
LeetCode
Algorithm
C++
算法
map
leetcode笔记
--Reverse Words in a String
题目:难度(Medium)Givenaninputstring,reversethestringwordbyword.Forexample,Givens="theskyisblue",return"blueisskythe".Update(2015-02-12):ForCprogrammers:Trytosolveitin-placeinO(1)space.Clarification(声明):Wh
u010366748
·
2016-02-24 18:00
LeetCode
python
String
leetcode笔记
--Simplify Path
题目:难度(Medium)Givenanabsolutepathforafile(Unix-style),simplifyit.Forexample,path="/home/",=>"/home"path="/a/./b/../../c/",=>"/c"CornerCases(极端条件):Didyouconsiderthecasewherepath="/../"?Inthiscase,yousho
u010366748
·
2016-02-24 18:00
LeetCode
python
String
stack
leetcode笔记
:Contains Duplicate
一.题目描述Givenanarrayofintegers,findifthearraycontainsanyduplicates.Yourfunctionshouldreturntrueifanyvalueappearsatleasttwiceinthearray,anditshouldreturnfalseifeveryelementisdistinct.二.题目分析题目的大意是,给定一个整数数
liyuefeilong
·
2016-02-24 18:00
LeetCode
C++
算法
map
sort
leetcode笔记
--Compare Version Numbers
题目:难度(Easy)Comparetwoversionnumbersversion1andversion2.Ifversion1>version2return1,ifversion1len(v2): length=len(v1) i=len(v2) whileiv2[i]: return1 elifv1[i]
u010366748
·
2016-02-24 16:00
LeetCode
String
leetcode笔记
--Count and Say
题目:难度(Easy)Thecount-and-saysequenceisthesequenceofintegersbeginningasfollows:1,11,21,1211,111221,...1isreadoffas"one1"or11.11isreadoffas"two1s"or21.21isreadoffas"one2,thenone1"or1211.Givenanintegern,g
u010366748
·
2016-02-24 15:00
LeetCode
String
递归
encode
leetcode笔记
--Length of Last Word
题目:难度(Easy)Givenastringsconsistsofupper/lower-casealphabetsandemptyspacecharacters'',returnthelengthoflastwordinthestring.Ifthelastworddoesnotexist,return0.Note:Awordisdefinedasacharactersequenceconsi
u010366748
·
2016-02-24 13:00
LeetCode
python
String
leetcode笔记
:Find the Duplicate Number
一.题目描述Givenanarraynumscontainingn+1integerswhereeachintegerisbetween1andn(inclusive),provethatatleastoneduplicateelementmustexist.Assumethatthereisonlyoneduplicatenumber,findtheduplicateone.Note:Youmu
liyuefeilong
·
2016-02-22 23:00
LeetCode
C++
算法
array
映射找环法
leetcode笔记
:Increasing Triplet Subsequence
一.题目描述Givenanunsortedarrayreturnwhetheranincreasingsubsequenceoflength3existsornotinthearray.Formallythefunctionshould:Returntrueifthereexistsi,j,ksuchthatarr[i]&nums){ intn=nums.size(); if(n<3)return
liyuefeilong
·
2016-02-22 17:00
LeetCode
C++
算法
array
子序列
leetcode笔记
:Longest Increasing Path in a Matrix
一.题目描述Givenanintegermatrix,findthelengthofthelongestincreasingpath.Fromeachcell,youcaneithermovetofourdirections:left,right,upordown.YoumayNOTmovediagonallyormoveoutsideoftheboundary(i.e.wrap-aroundis
liyuefeilong
·
2016-02-21 23:00
LeetCode
C++
算法
Matrix
DFS
leetcode笔记
:Missing Number
一.题目描述Givenanarraycontainingndistinctnumberstakenfrom0,1,2,...,n,findtheonethatismissingfromthearray.Forexample,Givennums=[0,1,3]return2.Note:Youralgorithmshouldruninlinearruntimecomplexity.Couldyouim
liyuefeilong
·
2016-02-19 14:00
LeetCode
C++
算法
异或
XOR
leetcode笔记
:Super Ugly Number
一.题目描述Writeaprogramtofindthenthsuperuglynumber.Superuglynumbersarepositivenumberswhoseallprimefactorsareinthegivenprimelistprimesofsizek.Forexample,[1,2,4,7,8,13,14,16,19,26,28,32]isthesequenceofthefi
liyuefeilong
·
2016-02-18 22:00
LeetCode
C++
算法
优先队列
丑数
leetcode笔记
:Coin Change
一.题目描述Youaregivencoinsofdifferentdenominationsandatotalamountofmoneyamount.Writeafunctiontocomputethefewestnumberofcoinsthatyouneedtomakeupthatamount.Ifthatamountofmoneycannotbemadeupbyanycombinationo
liyuefeilong
·
2016-02-18 16:00
LeetCode
C++
算法
dp
DFS
leetcode笔记
:Game of Life
一.题目描述AccordingtotheWikipedia’sarticle:“TheGameofLife,alsoknownsimplyasLife,isacellularautomatondevisedbytheBritishmathematicianJohnHortonConwayin1970.”Givenaboardwithmbyncells,eachcellhasaninitialsta
liyuefeilong
·
2016-02-18 00:00
LeetCode
C++
算法
Matrix
in-place
leetcode笔记
:Word Pattern
一.题目描述Givenapatternandastringstr,findifstrfollowsthesamepattern.Herefollowmeansafullmatch,suchthatthereisabijectionbetweenaletterinpatternandanon-emptywordinstr.Examples:pattern="abba",str="dogcatcatd
liyuefeilong
·
2016-02-15 15:00
LeetCode
C++
算法
String
map
leetcode笔记
:Wiggle Sort
一.题目描述Givenanunsortedarraynums,reorderitin-placesuchthatnums[0]=nums[2]=nums[2]=nums[i-1]当下标i是偶数时,nums[i]&nums){ if(nums.size()&nums){ if(nums.size()nums[i-1])) swap(nums[i],nums[i-1]); } } };四.小结后续有题
liyuefeilong
·
2016-02-14 14:00
LeetCode
Algorithm
C++
sort
greedy
leetcode笔记
:Majority Element
一.题目描述Givenanarrayofsizen,findthemajorityelement.Themajorityelementistheelementthatappearsmorethan⌊n/2⌋times.Youmayassumethatthearrayisnon-emptyandthemajorityelementalwaysexistinthearray.二.题目分析题目说到,给定
liyuefeilong
·
2016-02-03 22:00
LeetCode
C++
算法
array
element
leetcode笔记
:H-Index II
一.题目描述FollowupforH-Index:Whatifthecitationsarrayissortedinascendingorder?Couldyouoptimizeyouralgorithm?二.题目分析该题与H-Index一题的要求基本一致,只是多提供了一个条件,即传入的数组本身已经是升序排列的,因此实际上操作会方便许多,也无需再使用辅助数组。该题仍然可以使用H-Index方法从后
liyuefeilong
·
2016-02-01 16:00
LeetCode
C++
二分查找
算法
折半查找
leetcode笔记
:H-Index
一.题目描述Givenanarrayofcitations(eachcitationisanon-negativeinteger)ofaresearcher,writeafunctiontocomputetheresearcher’sh-index.Accordingtothedefinitionofh-indexonWikipedia:“Ascientisthasindexhifhofhis/h
liyuefeilong
·
2016-02-01 15:00
LeetCode
C++
算法
sort
H指数
leetcode笔记
:Patching Array
一.题目描述Givenasortedpositiveintegerarraynumsandanintegern,add/patchelementstothearraysuchthatanynumberinrange[1,n]inclusivecanbeformedbythesumofsomeelementsinthearray.Returntheminimumnumberofpatchesrequ
liyuefeilong
·
2016-01-31 22:00
LeetCode
Algorithm
C++
算法
array
leetcode笔记
:Perfect Squares
一.题目描述Givenapositiveintegern,findtheleastnumberofperfectsquarenumbers(forexample,1,4,9,16,...)whichsumton.Forexample,givenn=12,return3because12=4+4+4;givenn=13,return2because13=4+9.二.题目分析该题目的大意是,给出一个目
liyuefeilong
·
2016-01-29 23:00
LeetCode
C++
dp
动态规划
Square
leetcode笔记
:Reverse Bits
一.题目描述Reversebitsofagiven32bitsunsignedinteger.Forexample,giveninput43261596(representedinbinaryas00000010100101000001111010011100),return964176192(representedinbinaryas0011100101111000001010010100000
liyuefeilong
·
2016-01-29 17:00
LeetCode
位运算
C++
算法
bit
leetcode笔记
:Count Primes
一.题目描述Countthenumberofprimenumberslessthananon-negativenumber,n.二.题目分析题目有很多tips,大意是算出2~n之间有多少个素数。若使用暴力法只会是超时,而正确的思路来自著名的埃拉托斯特尼筛法。简单来说,要得到自然数n以内的全部素数,必须把不大于sqrt(n)的所有素数的倍数剔除,剩下的就是素数。更多关于埃拉托斯特尼筛法,参照:htt
liyuefeilong
·
2016-01-27 23:00
LeetCode
C++
算法
Prime
Eratosthen
leetcode笔记
:Length of Last Word
一.题目描述Givenastringsconsistsofupper/lower-casealphabetsandemptyspacecharacters’‘,returnthelengthoflastwordinthestring.Ifthelastworddoesnotexist,return0.Note:Awordisdefinedasacharactersequenceconsistsof
liyuefeilong
·
2016-01-27 16:00
LeetCode
C++
算法
String
length
leetcode笔记
:Word Break
一.题目描述Givenastringsandadictionaryofwordsdict,determineifscanbesegmentedintoaspace-separatedsequenceofoneormoredictionarywords.Forexample,givens="leetcode",dict=["leet","code"].Returntruebecause"leetco
liyuefeilong
·
2016-01-25 23:00
LeetCode
Algorithm
C++
算法
String
leetcode笔记
:Move Zeroes
一.题目描述Givenanarraynums,writeafunctiontomoveall0'stotheendofitwhilemaintainingtherelativeorderofthenon-zeroelements.Forexample,givennums=[0,1,0,3,12],aftercallingyourfunction,numsshouldbe[1,3,12,0,0].N
liyuefeilong
·
2016-01-23 11:00
LeetCode
Algorithm
C++
算法
inplace
leetcode笔记
:Range Sum Query - Mutable
一.题目描述Givenanintegerarraynums,findthesumoftheelementsbetweenindicesiandj(i≤j),inclusive.Theupdate(i,val)functionmodifiesnumsbyupdatingtheelementatindexitoval.Example:Givennums=[1,3,5]sumRange(0,2)->9
liyuefeilong
·
2016-01-21 01:00
LeetCode
C++
算法
array
树状数组
leetcode笔记
:Range Sum Query - Immutable
一.题目描述Givenanintegerarraynums,findthesumoftheelementsbetweenindicesiandj(i≤j),inclusive.Example:Givennums=[-2,0,3,-5,2,-1]sumRange(0,2)->1 sumRange(2,5)->-1 sumRange(0,5)->-3二.题目分析给定一个数组nums,求出下标i和j之间
liyuefeilong
·
2016-01-20 23:00
LeetCode
C++
算法
SUM
range
leetcode笔记
:Divide Two Integers
一.题目描述Dividetwointegerswithoutusingmultiplication,divisionandmodoperator.Ifitisoverflow,returnMAX_INT.二.题目分析题目的意思简单明了,就是要求不使用乘法、除法和取余mod,输入两个整数,输出除法操作的结果。出去乘除法,剩下的只有加减法和位运算,这是不难想到的,而直接使用减法,对被除数逐次减去除数大
liyuefeilong
·
2016-01-20 22:00
LeetCode
位运算
C++
算法
divide
leetcode笔记
:ZigZag Conversion
一.题目描述Thestring“PAYPALISHIRING”iswritteninazigzagpatternonagivennumberofrowslikethis:(youmaywanttodisplaythispatterninafixedfontforbetterlegibility)PAHN APLSIIG YIRAndthenreadlinebyline:"PAHNAPLSIIGYI
liyuefeilong
·
2016-01-18 23:00
LeetCode
Algorithm
C++
String
ZigZag
leetcode笔记
:Find Median from Data Stream
一.题目描述Medianisthemiddlevalueinanorderedintegerlist.Ifthesizeofthelistiseven,thereisnomiddlevalue.Sothemedianisthemeanofthetwomiddlevalue.Examples:[2,3,4],themedianis3[2,3],themedianis(2+3)/2=2.5Design
liyuefeilong
·
2016-01-14 22:00
LeetCode
Algorithm
C++
Queue
优先队列
leetcode笔记
:Bulls and Cows
一.题目描述YouareplayingthefollowingBullsandCowsgamewithyourfriend:Youwritedownanumberandaskyourfriendtoguesswhatthenumberis.Eachtimeyourfriendmakesaguess,youprovideahintthatindicateshowmanydigitsinsaidgue
liyuefeilong
·
2016-01-13 21:00
LeetCode
Algorithm
C++
算法
String
leetcode笔记
:Bulb Switcher
一.题目描述Therearenbulbsthatareinitiallyoff.Youfirstturnonallthebulbs.Then,youturnoffeverysecondbulb.Onthethirdround,youtoggleeverythirdbulb(turningonifit’sofforturningoffifit’son).Forthenthround,youonlyt
liyuefeilong
·
2016-01-13 16:00
LeetCode
Algorithm
C++
算法
leetcode笔记
:Integer to English Words
一.题目描述Convertanon-negativeintegertoitsenglishwordsrepresentation.Giveninputisguaranteedtobelessthan231-1.Forexample,123->"OneHundredTwentyThree" 12345->"TwelveThousandThreeHundredFortyFive" 1234567->"
liyuefeilong
·
2016-01-12 18:00
LeetCode
Algorithm
C++
算法
String
上一页
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
其他