当前位置:首页 » leetcode

leetcode

1
阅读

LeetCode #116 - Populating Next Right Pointers in Each Node - Medium

Problem[code]GivenabinarytreestructTreeLinkNode{TreeLinkNode*left;TreeLinkNode*right;TreeLinkNode*next;}Populateeachnextpointertopointtoitsnextrightnode.Ifther...
来源 2016-11-12 21:54
1
阅读

LeetCode #199 - Binary Tree Right Side View - Medium

Problem[code]Givenabinarytree,imagineyourselfstandingontherightsideofit,returnthevaluesofthenodesyoucanseeorderedfromtoptobottom.Example[code]1---/\23---\\54--...
来源 2016-11-12 21:35
4
阅读

leetcode_[python/C++]_424_Longest Repeating Character Replacement

题目链接【题目】GivenastringthatconsistsofonlyuppercaseEnglishletters,youcanreplaceanyletterinthestringwithanotherletteratmostktimes.Findthelengthofalongestsub...
来源 2016-11-12 21:30
4
阅读

LeetCode #394 - Decode String -Medium

Problem[code]Givenanencodedstring,returnit'sdecodedstring.Theencodingruleis:k[encoded_string],wheretheencoded_stringinsidethesquarebracketsisbeingrepeatedexact...
来源 2016-11-12 10:21
2
阅读

382.+Linked+List+Random+Node(返回链表中随机一个节点的值)

Givenasinglylinkedlist,returnarandomnode'svaluefromthelinkedlist.Eachnodemusthavethesameprobabilityofbeingchosen.Followup:Whatifthelinkedlistisextremelylargean...
来源 2016-11-12 00:32
1
阅读

LeetCode #108 - Convert Sorted Array to Binary Search Tree -Medium

Problem[code]Givenanarraywhereelementsaresortedinascendingorder,convertittoaheightbalancedBST.Example[code]Input:[1,2,3]Output:1/\23Algorithm整理一下题意:给...
来源 2016-11-12 00:16
5
阅读

238.+Product+of+Array+Except+Self+(计算整型数组中除了某元素之外所有元素的积)

Givenanarrayofnintegerswheren1,nums,returnanarrayoutputsuchthatoutput[i]isequaltotheproductofalltheelementsofnumsexceptnums[i].SolveitwithoutdivisionandinO(n)....
来源 2016-11-11 23:47
3
阅读

167.+Two+Sum+II+-+Input+array+is+sorted+(在有序数组中确定和为给定值的两个元素的下标)

Givenanarrayofintegersthatisalreadysortedinascendingorder,findtwonumberssuchthattheyadduptoaspecifictargetnumber.ThefunctiontwoSumshouldreturnindicesofthetwonu...
来源 2016-11-11 21:41
2
阅读

leetcode_[python/java/javascript/C++]_401_Binary Watch(二进制手表)

题目链接【题目】Abinarywatchhas4LEDsonthetopwhichrepresentthehours(0-11),andthe6LEDsonthebottomrepresenttheminutes(0-59).EachLEDrepresentsazeroorone,withthelea...
来源 2016-11-11 14:34
1
阅读

LeetCode 22. Generate Parentheses

题目描述Givennpairsofparentheses,writeafunctiontogenerateallcombinationsofwell-formedparentheses.Forexample,givenn=3,asolutionsetis:[“((()))”,“(()())”,“((...
来源 2016-11-10 22:31
3
阅读

260.+Single+Number+III+(找到数组中仅出现一次的两个数)

Givenanarrayofnumbersnums,inwhichexactlytwoelementsappearonlyonceandalltheotherelementsappearexactlytwice.Findthetwoelementsthatappearonlyonce.Forexample:Given...
来源 2016-11-10 10:08
1
阅读

LeetCode #337 - House Robber III - Medium

Problem[code]Thethiefhasfoundhimselfanewplaceforhisthieveryagain.Thereisonlyoneentrancetothisarea,calledtheroot.Besidestheroot,eachhousehasoneandonlyoneparen...
来源 2016-11-09 18:54
1
阅读

LeetCode #100 - Same Tree - Easy

Problem[code]Giventwobinarytrees,writeafunctiontocheckiftheyareequalornot.Twobinarytreesareconsideredequaliftheyarestructurallyidenticalandthenodeshavethesamev...
来源 2016-11-09 18:36
3
阅读

leetcode--twosum

[code]deftwoSum(nums,target):dict={}forindexinxrange(0,len(nums)):num=nums[index]ifnumindict:return[dict[num],index]else:dict[target-num]=indexprint('wecannotf...
来源 2016-11-09 18:29
2
阅读

413.+Arithmetic+Slices+(找等差数列)

Asequenceofnumberiscalledarithmeticifitconsistsofatleastthreeelementsandifthedifferencebetweenanytwoconsecutiveelementsisthesame.Forexample,thesearearithmetics...
来源 2016-11-09 11:24
3
阅读

406.+Queue+Reconstruction+by+Height(根据身高重排队列)

Supposeyouhavearandomlistofpeoplestandinginaqueue.Eachpersonisdescribedbyapairofintegers(h,k),wherehistheheightofthepersonandkisthenumberofpeopleinfrontofthisp...
来源 2016-11-09 00:32
2
阅读

LeetCode10. Regular Expression Matching

题目:简单正则表达式匹配Implementregularexpressionmatchingwithsupportfor'.'and'*'.'.'Matchesanysinglecharacter.'*'Matcheszeroormoreoftheprecedingelement.Themat...
来源 2016-11-08 19:56
2
阅读

LeetCode25. Reverse Nodes in k-Group

题目:对一个链表的长度为k的块进行reverse,要求常数空间。Givenalinkedlist,reversethenodesofalinkedlistkatatimeandreturnitsmodifiedlist.Ifthenumberofnodesisnotam...
来源 2016-11-08 19:36
2
阅读

Leetcode6: ZigZag Conversion

题目要求如图,输入参数将会有2个,一个是字符串,另外一个是要求分几行显示开始解题后,发现规律是,每一个完整竖列的第一个元素,和,上一个元素,间隔都是2n-2,这个2n-...
来源 2016-11-08 14:07
1
阅读

LeetCode #104 - Maximum Depth of Binary Tree - Easy

Problem[code]Givenabinarytree,finditsmaximumdepth.Themaximumdepthisthenumberofnodesalongthelongestpathfromtherootnodedowntothefarthestleafnode.Example[code]1/\...
来源 2016-11-07 21:40
2
阅读

LeetCode144. Binary Tree Preorder Traversal

题目Givenabinarytree,returnthepreordertraversalofitsnodes’values.Forexample:Givenbinarytree{1,#,2,3},[code]1\2/3return[1,2,3].Note:Recursivesolutionistrivial,...
来源 2016-11-07 17:23
2
阅读

LeetCode403. Frog Jump

题目:Afrogiscrossingariver.Theriverisdividedintoxunitsandateachunittheremayormaynotexistastone.Thefrogcanjumponastone,butitmustnotjumpintothewater.Givenalisto...
来源 2016-11-07 15:29
2
阅读

LeetCode112. Path Sum

题目Givenabinarytreeandasum,determineifthetreehasaroot-to-leafpathsuchthataddingupallthevaluesalongthepathequalsthegivensum.Forexample:Giventhebelowbinarytreea...
来源 2016-11-07 15:26
2
阅读

Leetcode9: Palindrome Number

一个回数的题目.......点进去的时候觉得很简单,数字转字符串,分分钟搞定。。。。结果一看补充说明,懵逼了,不准使用额外空间。。注意整数溢出问题不准使用额外...
来源 2016-11-07 15:00
6
阅读

LeetCode329. Longest Increasing Path in a Matrix

题目:Givenanintegermatrix,findthelengthofthelongestincreasingpath.Fromeachcell,youcaneithermovetofourdirections:left,right,upordown.YoumayNOTmovediagonallyorm...
来源 2016-11-07 14:28