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笔记
103.
leetcode笔记
(1~60)
d1leet1:两数之和https://leetcode-cn.com/problems/two-sum给定nums=[2,7,11,15],target=9因为nums[0]+nums[1]=2+7=9所以返回[0,1]【hashmap存储】classSolution:deftwoSum(self,nums:List[int],target:int)->List[int]:#边界值判断ifnot
十里江城
·
2020-05-11 22:34
LeetCode笔记
(数组双指针,同时遍历左右子树,最大子序和)
121.买卖股票的最佳时机*-easy还是太菜,想了很久用双指针来记录最小值和最大利润,每进来一个数就要比较是否为最小数,并且比较此时卖出是否比之前卖出赚的更多//14.57//15.25classSolution{public:intmaxProfit(vector&prices){if(prices.size()sum){sum=prices[i]-small;}if(small>prices
feitianguaishou
·
2020-04-26 14:15
leetcode
LeetCode笔记
:435. Non-overlapping Intervals
问题:Givenacollectionofintervals,findtheminimumnumberofintervalsyouneedtoremovetomaketherestoftheintervalsnon-overlapping.Note:1、Youmayassumetheinterval'sendpointisalwaysbiggerthanitsstartpoint.2、Interv
Cloudox_
·
2020-04-13 13:10
LeetCode笔记
:728. Self Dividing Numbers
问题(Easy):Aself-dividingnumberisanumberthatisdivisiblebyeverydigititcontains.Forexample,128isaself-dividingnumberbecause128%1==0,128%2==0,and128%8==0.Also,aself-dividingnumberisnotallowedtocontainthedi
Cloudox_
·
2020-04-13 04:39
LeetCode笔记
:217. Contains Duplicate
题目:Givenanarrayofintegers,findifthearraycontainsanyduplicates.Yourfunctionshouldreturntrueifanyvalueappearsatleasttwiceinthearray,anditshouldreturnfalseifeveryelementisdistinct.大意:给出一个int型的数组,判断数组是否包含
Cloudox_
·
2020-04-12 00:17
LeetCode笔记
:463. Island Perimeter
问题(Easy):Youaregivenamapinformofatwo-dimensionalintegergridwhere1representslandand0representswater.Gridcellsareconnectedhorizontally/vertically(notdiagonally).Thegridiscompletelysurroundedbywater,andt
Cloudox_
·
2020-04-11 19:26
LeetCode笔记
:598. Range Addition II
问题(Easy):Givenanm*nmatrixMinitializedwithall0'sandseveralupdateoperations.Operationsarerepresentedbya2Darray,andeachoperationisrepresentedbyanarraywithtwopositiveintegersaandb,whichmeansM[i][j]shouldb
Cloudox_
·
2020-04-10 23:57
LeetCode笔记
:482. License Key Formatting
问题:NowyouaregivenastringS,whichrepresentsasoftwarelicensekeywhichwewouldliketoformat.ThestringSiscomposedofalphanumericalcharactersanddashes.Thedashessplitthealphanumericalcharacterswithinthestringint
Cloudox_
·
2020-04-02 19:39
LeetCode笔记
:144. Binary Tree Preorder Traversal
问题:Givenabinarytree,returnthepreordertraversalofitsnodes'values.Forexample:Givenbinarytree{1,#,2,3},image.pngreturn[1,2,3].Note:Recursivesolutionistrivial,couldyoudoititeratively?大意:给出一个二叉树,返回节点值的前序遍历
Cloudox_
·
2020-04-02 08:48
LeetCode笔记
:500. Keyboard Row
问题(Easy):GivenaListofwords,returnthewordsthatcanbetypedusinglettersofalphabetononlyonerow'sofAmericankeyboardliketheimagebelow.Example1:Input:["Hello","Alaska","Dad","Peace"]Output:["Alaska","Dad"]Not
Cloudox_
·
2020-04-01 15:07
LeetCode笔记
:496. Next Greater Element I
问题(Easy):Youaregiventwoarrays(withoutduplicates)nums1andnums2wherenums1’selementsaresubsetofnums2.Findallthenextgreaternumbersfornums1'selementsinthecorrespondingplacesofnums2.TheNextGreaterNumberofan
Cloudox_
·
2020-04-01 15:35
LeetCode笔记
:485. Max Consecutive Ones
问题(Easy):Givenabinaryarray,findthemaximumnumberofconsecutive1sinthisarray.Example1:Input:[1,1,0,1,1,1]Output:3Explanation:Thefirsttwodigitsorthelastthreedigitsareconsecutive1s.Themaximumnumberofconsec
Cloudox_
·
2020-03-30 22:39
LeetCode笔记
:371. Sum of Two Integers
问题:Calculatethesumoftwointegersaandb,butyouarenotallowedtousetheoperator+and-.Example:Givena=1andb=2,return3.大意:计算a和b两个整数的和,但是不能用+或-运算符。比如:给出a=1和b=2,返回3.思路:这道题乍看之下很简单,计算两个数之和嘛,但问题在于不能直接使用加号和减号,这就尴尬了,不
Cloudox_
·
2020-03-30 10:32
LeetCode笔记
--动态规划
动态规划最优子结构:问题的最优解由相关子问题的最优解组合而成,而这些子问题可以独立求解。即一个问题的最优解包含其子问题的最优解。独立求解的理解:如算法导论P218中所说,要保证分解后得到的子问题之间可以独立求解,也即同一分解中不同子问题所用资源之间没有交集动态规划与分治动态规划与分治法很相似,都是通过组合子问题的解来解原问题,但是分治法的子问题之间是不相交的,没有公共子子问题,比如归并排序,每一次
慕北人
·
2020-03-30 01:18
LeetCode笔记
:232. Implement Queue using Stacks
问题:Implementthefollowingoperationsofaqueueusingstacks.push(x)--Pushelementxtothebackofqueue.pop()--Removestheelementfrominfrontofqueue.peek()--Getthefrontelement.empty()--Returnwhetherthequeueisempty.
Cloudox_
·
2020-03-28 03:44
LeetCode笔记
:121. Best Time to Buy and Sell Stock
问题:Sayyouhaveanarrayforwhichtheithelementisthepriceofagivenstockondayi.Ifyouwereonlypermittedtocompleteatmostonetransaction(ie,buyoneandselloneshareofthestock),designanalgorithmtofindthemaximumprofit.
Cloudox_
·
2020-03-28 01:45
LeetCode笔记
:19. Remove Nth Node From End of List
问题:Givenalinkedlist,removethenthnodefromtheendoflistandreturnitshead.Forexample,Givenlinkedlist:1->2->3->4->5,andn=2.Afterremovingthesecondnodefromtheend,thelinkedlistbecomes1->2->3->5.Note:Givennwill
Cloudox_
·
2020-03-26 22:02
LeetCode笔记
:202. Happy Number
问题:Writeanalgorithmtodetermineifanumberis"happy".Ahappynumberisanumberdefinedbythefollowingprocess:Startingwithanypositiveinteger,replacethenumberbythesumofthesquaresofitsdigits,andrepeattheprocessunt
Cloudox_
·
2020-03-26 12:46
LeetCode笔记
:617. Merge Two Binary Trees
问题(Easy):Giventwobinarytreesandimaginethatwhenyouputoneofthemtocovertheother,somenodesofthetwotreesareoverlappedwhiletheothersarenot.Youneedtomergethemintoanewbinarytree.Themergeruleisthatiftwonodesov
Cloudox_
·
2020-03-26 04:07
LeetCode笔记
:526. Beautiful Arrangement
问题:SupposeyouhaveNintegersfrom1toN.WedefineabeautifularrangementasanarraythatisconstructedbytheseNnumberssuccessfullyifoneofthefollowingistruefortheithposition(1≤i≤N)inthisarray:Thenumberattheithposit
Cloudox_
·
2020-03-25 13:51
LeetCode笔记
:223. Rectangle Area
问题:Findthetotalareacoveredbytworectilinearrectanglesina2Dplane.Eachrectangleisdefinedbyitsbottomleftcornerandtoprightcornerasshowninthefigure.image.pngAssumethatthetotalareaisneverbeyondthemaximumposs
Cloudox_
·
2020-03-25 05:46
LeetCode笔记
:263. Ugly Number
问题:Writeaprogramtocheckwhetheragivennumberisanuglynumber.Uglynumbersarepositivenumberswhoseprimefactorsonlyinclude2,3,5.Forexample,6,8areuglywhile14isnotuglysinceitincludesanotherprimefactor7.Notethat
Cloudox_
·
2020-03-24 23:37
LeetCode笔记
:237. Delete Node in a Linked List
题目:Writeafunctiontodeleteanode(exceptthetail)inasinglylinkedlist,givenonlyaccesstothatnode.Supposedthelinkedlistis1->2->3->4andyouaregiventhethirdnodewithvalue3,thelinkedlistshouldbecome1->2->4afterca
Cloudox_
·
2020-03-23 00:45
LeetCode笔记
:225. Implement Stack using Queues
问题:Implementthefollowingoperationsofastackusingqueues.push(x)--Pushelementxontostack.pop()--Removestheelementontopofthestack.top()--Getthetopelement.empty()--Returnwhetherthestackisempty.Notes:Youmust
Cloudox_
·
2020-03-22 18:42
LeetCode笔记
:383. Ransom Note
问题:Givenanarbitraryransomnotestringandanotherstringcontaininglettersfromallthemagazines,writeafunctionthatwillreturntrueiftheransomnotecanbeconstructedfromthemagazines;otherwise,itwillreturnfalse.Each
Cloudox_
·
2020-03-22 09:20
LeetCode笔记
:343. Integer Break
问题:Givenapositiveintegern,breakitintothesumofatleasttwopositiveintegersandmaximizetheproductofthoseintegers.Returnthemaximumproductyoucanget.Forexample,givenn=2,return1(2=1+1);givenn=10,return36(10=3+
Cloudox_
·
2020-03-22 07:34
LeetCode笔记
:292.Nim Game
问题:YouareplayingthefollowingNimGamewithyourfriend:Thereisaheapofstonesonthetable,eachtimeoneofyoutaketurnstoremove1to3stones.Theonewhoremovesthelaststonewillbethewinner.Youwilltakethefirstturntoremove
Cloudox_
·
2020-03-20 08:03
LeetCode笔记
:206. Reverse Linked List
题目:Reverseasinglylinkedlist.大意:反转一个简单链表。思路:题目的意思就是给出一个链表,本来是从头指向尾的,现在要你做成从尾指向头,并且返回原来的尾,现在的头。这个肯定是要用递归或者迭代来做。只要屡清楚过程,会比较绕。大体的流程就是,把下一个节点的next指向自己,一个个迭代、递归下去,最后返回最后的原来的尾节点他山之石:这里给出Discuss中最火的方法。迭代实现:pu
Cloudox_
·
2020-03-18 11:13
LeetCode笔记
:400. Nth Digit
问题:Findthenthdigitoftheinfiniteintegersequence1,2,3,4,5,6,7,8,9,10,11,...Note:nispositiveandwillfitwithintherangeofa32-bitsignedinteger(nreduce+num*i){lastNum=lastNum+num;reduce=reduce+num*i;num=num*1
Cloudox_
·
2020-03-17 23:20
LeetCode笔记
:100. Same Tree
题目:Giventwobinarytrees,writeafunctiontocheckiftheyareequalornot.Twobinarytreesareconsideredequaliftheyarestructurallyidenticalandthenodeshavethesamevalue.大意:给出两个二叉树,写一个函数来检查两者是否相等。所谓相等,是指他们结构相同且节点有同样的
Cloudox_
·
2020-03-17 22:42
LeetCode笔记
:169. Majority Element
题目:Givenanarrayofsizen,findthemajorityelement.Themajorityelementistheelementthatappearsmorethan⌊n/2⌋times.Youmayassumethatthearrayisnon-emptyandthemajorityelementalwaysexistinthearray.大意:给出一个尺寸为n的数组,找
Cloudox_
·
2020-03-14 18:31
LeetCode笔记
:406. Queue Reconstruction by Height
问题:Supposeyouhavearandomlistofpeoplestandinginaqueue.Eachpersonisdescribedbyapairofintegers(h,k),wherehistheheightofthepersonandkisthenumberofpeopleinfrontofthispersonwhohaveaheightgreaterthanorequalt
Cloudox_
·
2020-03-10 16:36
LeetCode笔记
:118. 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]]大意:给出一个行数,生出对应行数的杨辉三角形。比如,给出行数=5。返回[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,
Cloudox_
·
2020-03-10 02:09
LeetCode笔记
:67. Add Binary
问题:Giventwobinarystrings,returntheirsum(alsoabinarystring).Forexample,a="11"b="1"Return"100".大意:给出两个二进制字符串,返回它们的和(同样是二进制字符串)。例子:a="11"b="1"返回"100".思路:这其实就是一个模拟二进制加法的问题。如果某一位两个数都是0,结果的这一位也为0,有一个1就是1,如果
Cloudox_
·
2020-03-09 18:03
LeetCode笔记
:378. Kth Smallest Element in a Sorted Matrix
问题:Givenanxnmatrixwhereeachoftherowsandcolumnsaresortedinascendingorder,findthekthsmallestelementinthematrix.Notethatitisthekthsmallestelementinthesortedorder,notthekthdistinctelement.Example:image.pn
Cloudox_
·
2020-03-09 07:59
LeetCode笔记
:508. Most Frequent Subtree Sum
问题:Giventherootofatree,youareaskedtofindthemostfrequentsubtreesum.Thesubtreesumofanodeisdefinedasthesumofallthenodevaluesformedbythesubtreerootedatthatnode(includingthenodeitself).Sowhatisthemostfrequ
Cloudox_
·
2020-03-09 06:09
LeetCode笔记
:498. Diagonal Traverse
问题:GivenamatrixofMxNelements(Mrows,Ncolumns),returnallelementsofthematrixindiagonalorderasshowninthebelowimage.Example:Input:[[1,2,3],[4,5,6],[7,8,9]]Output:[1,2,4,7,5,3,6,8,9]Explanation:image.pngNot
Cloudox_
·
2020-03-08 07:08
LeetCode笔记
:386. Lexicographical Numbers
问题:Givenanintegern,return1-ninlexicographicalorder.Forexample,given13,return:[1,10,11,12,13,2,3,4,5,6,7,8,9].Pleaseoptimizeyouralgorithmtouselesstimeandspace.Theinputsizemaybeaslargeas5,000,000.思路:给出一
Cloudox_
·
2020-03-05 23:39
LeetCode笔记
:89. Gray Code
问题:Thegraycodeisabinarynumeralsystemwheretwosuccessivevaluesdifferinonlyonebit.Givenanon-negativeintegernrepresentingthetotalnumberofbitsinthecode,printthesequenceofgraycode.Agraycodesequencemustbegin
Cloudox_
·
2020-03-04 14:52
LeetCode笔记
:455. Assign Cookies
问题:Assumeyouareanawesomeparentandwanttogiveyourchildrensomecookies.But,youshouldgiveeachchildatmostonecookie.Eachchildihasagreedfactorgi,whichistheminimumsizeofacookiethatthechildwillbecontentwith;and
Cloudox_
·
2020-03-04 05:38
LeetCode笔记
:409. Longest Palindrome
问题:Givenastringwhichconsistsoflowercaseoruppercaseletters,findthelengthofthelongestpalindromesthatcanbebuiltwiththoseletters.Thisiscasesensitive,forexample"Aa"isnotconsideredapalindromehere.Note:Assum
Cloudox_
·
2020-03-04 00:41
LeetCode笔记
:319. Bulb Switcher
问题:Therearenbulbsthatareinitiallyoff.Youfirstturnonallthebulbs.Then,youturnoffeverysecondbulb.Onthethirdround,youtoggleeverythirdbulb(turningonifit'sofforturningoffifit'son).Fortheithround,youtoggleev
Cloudox_
·
2020-03-03 07:13
LeetCode笔记
:413. Arithmetic Slices
问题:Asequenceofnumberiscalledarithmeticifitconsistsofatleastthreeelementsandifthedifferencebetweenanytwoconsecutiveelementsisthesame.Forexample,thesearearithmeticsequence:1,3,5,7,97,7,7,73,-1,-5,-9Thef
Cloudox_
·
2020-03-01 18:30
LeetCode笔记
:160. Intersection of Two Linked Lists
问题:Writeaprogramtofindthenodeatwhichtheintersectionoftwosinglylinkedlistsbegins.Forexample,thefollowingtwolinkedlists:image.pngbegintointersectatnodec1.Notes:Ifthetwolinkedlistshavenointersectionatall
Cloudox_
·
2020-02-29 14:48
LeetCode笔记
:258.Add Digits
问题:Givenanon-negativeintegernum,repeatedlyaddallitsdigitsuntiltheresulthasonlyonedigit.Forexample:Givennum=38,theprocessislike:3+8=11,1+1=2.Since2hasonlyonedigit,returnit.Followup:Couldyoudoitwithouta
Cloudox_
·
2020-02-27 15:47
LeetCode笔记
:374. Guess Number Higher or Lower
问题:WeareplayingtheGuessGame.Thegameisasfollows:Ipickanumberfrom1ton.YouhavetoguesswhichnumberIpicked.Everytimeyouguesswrong,I'lltellyouwhetherthenumberishigherorlower.Youcallapre-definedAPIguess(intnu
Cloudox_
·
2020-02-26 13:31
LeetCode笔记
:561. Array Partition I
问题(Easy):Givenanarrayof2nintegers,yourtaskistogrouptheseintegersintonpairsofinteger,say(a1,b1),(a2,b2),...,(an,bn)whichmakessumofmin(ai,bi)forallifrom1tonaslargeaspossible.Example1:Input:[1,4,3,2]Outp
Cloudox_
·
2020-02-25 20:06
LeetCode笔记
:637. Average of Levels in Binary Tree
问题(Easy):Givenanon-emptybinarytree,returntheaveragevalueofthenodesoneachlevelintheformofanarray.Example1:Input:Output:[3,14.5,11]Explanation:Theaveragevalueofnodesonlevel0is3,onlevel1is14.5,andonlevel
Cloudox_
·
2020-02-24 07:24
LeetCode笔记
:46. Permutations
问题:Givenacollectionofdistinctnumbers,returnallpossiblepermutations.Forexample,[1,2,3]havethefollowingpermutations:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]大意:给出一个不同数字的集合,返回所有可能的排列。比如:[1,2,3]有下
Cloudox_
·
2020-02-23 00:28
LeetCode笔记
:557. Reverse Words in a String III
问题(Easy):Givenastring,youneedtoreversetheorderofcharactersineachwordwithinasentencewhilestillpreservingwhitespaceandinitialwordorder.Example1:Input:"Let'stakeLeetCodecontest"Output:"s'teLekatedoCteeLt
Cloudox_
·
2020-02-22 04:09
上一页
3
4
5
6
7
8
9
10
下一页
按字母分类:
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
其他