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每日一题
:链表排序
问题描述SortalinkedlistinO(nlogn)timeusingconstantspacecomplexity.问题分析本体要求在常数空间复杂度和O(nlogn)的时间复杂度来排序链表满足这种要求的就是归并排序和快速排序,这里给出的是快速排序。代码实现publicListNodesortList(ListNodehead){listQuickSort(head,null);return
yoshino
·
2020-02-12 21:24
LeetCode每日一题
:通过有序链表建立二叉搜索树
问题描述Givenasinglylinkedlistwhereelementsaresortedinascendingorder,convertittoaheightbalancedBST.问题分析这题让我们通过一个有序的链表建立二叉搜索树BST,注意到BST的中序排列必定是有序的,所以我们通过快慢指针寻找链表的中点再建立树就可以了。代码实现publicTreeNodesortedListToBS
yoshino
·
2020-02-10 20:19
LeetCode每日一题
:分糖问题
问题描述ThereareNchildrenstandinginaline.Eachchildisassignedaratingvalue.Youaregivingcandiestothesechildrensubjectedtothefollowingrequirements:Eachchildmusthaveatleastonecandy.Childrenwithahigherratingget
yoshino
·
2020-02-05 12:35
LeetCode每日一题
:length of last word
问题描述Givenastringsconsistsofupper/lower-casealphabetsandemptyspacecharacters'',returnthelengthoflastwordinthestring.Ifthelastworddoesnotexist,return0.Note:Awordisdefinedasacharactersequenceconsistsofno
yoshino
·
2020-01-07 18:15
LeetCode每日一题
:克隆一个图
问题描述Cloneanundirectedgraph.Eachnodeinthegraphcontainsalabelandalistofitsneighbors.OJ'sundirectedgraphserialization:Nodesarelabeleduniquely.Weuse¥asaseparatorforeachnode,and,asaseparatorfornodelabeland
yoshino
·
2020-01-07 08:35
LeetCode每日一题
:二叉树最小深度
问题描述Givenabinarytree,finditsminimumdepth.Theminimumdepthisthenumberofnodesalongtheshortestpathfromtherootnodedowntothenearestleafnode.问题分析求二叉树的最小深度,一般就是到达叶子节点的最短路径,用递归返回节点即可。代码实现publicclassSolution{pu
yoshino
·
2020-01-05 13:56
LeetCode每日一题
:valid number
问题描述Validateifagivenstringisnumeric.Someexamples:"0"=>true"0.1"=>true"abc"=>false"1a"=>false"2e10"=>trueNote:Itisintendedfortheproblemstatementtobeambiguous.Youshouldgatherallrequirementsupfrontbefore
yoshino
·
2020-01-04 12:27
LeetCode每日一题
:swap nodes in pairs
问题描述Givenalinkedlist,swapeverytwoadjacentnodesandreturnitshead.Forexample,Given1->2->3->4,youshouldreturnthelistas2->1->4->3.Youralgorithmshoulduseonlyconstantspace.Youmaynotmodifythevaluesinthelist,o
yoshino
·
2020-01-01 19:45
LeetCode每日一题
:reverse integer
问题描述Reversedigitsofaninteger.Example1:x=123,return321Example2:x=-123,return-321clicktoshowspoilers.Haveyouthoughtaboutthis?Herearesomegoodquestionstoaskbeforecoding.Bonuspointsforyouifyouhavealreadyth
yoshino
·
2019-12-26 04:14
LeetCode每日一题
:simplify path
问题描述Givenanabsolutepathforafile(Unix-style),simplifyit.Forexample,path="/home/",=>"/home"path="/a/./b/../../c/",=>"/c"clicktoshowcornercases.CornerCases:Didyouconsiderthecasewherepath="/../"?Inthiscas
yoshino
·
2019-12-25 20:37
LeetCode每日一题
:first missing positive
问题描述Givenanunsortedintegerarray,findthefirstmissingpositiveinteger.Forexample,Given[1,2,0]return3,and[3,4,-1,1]return2.YouralgorithmshouldruninO(n)timeandusesconstantspace.问题分析这道题目有很多的方法来做,比如排序或者hashM
yoshino
·
2019-12-21 10:53
LeetCode每日一题
:二叉树层次遍历
问题描述Givenabinarytree,returnthebottom-uplevelordertraversalofitsnodes'values.(ie,fromlefttoright,levelbylevelfromleaftoroot).Forexample:Givenbinarytree{3,9,20,¥,¥,15,7},3/920/157returnitsbottom-uplevel
yoshino
·
2019-12-21 05:08
LeetCode每日一题
14. 最接近的三数之和
LeetCode题目给定一个包括n个整数的数组nums和一个目标值target。找出nums中的三个整数,使得它们的和与target最接近。返回这三个数的和。假定每组输入只存在唯一答案。例如,给定数组nums=[-1,2,1,-4],和target=1.与target最接近的三个数的和为2.(-1+2+1=2).分析这是一道中等难度的题,是之前三数之和的变种,条件复杂了一些,但总体的思路没有变化.
FesonX
·
2019-12-19 15:32
LeetCode每日一题
:count and say
问题描述Thecount-and-saysequenceisthesequenceofintegersbeginningasfollows:1,11,21,1211,111221,...1isreadoffas"one1"or11.11isreadoffas"two1s"or21.21isreadoffas"one2,thenone1"or1211.Givenanintegern,generate
yoshino
·
2019-12-19 13:07
LeetCode每日一题
:分词2
问题描述Givenastringsandadictionaryofwordsdict,addspacesinstoconstructasentencewhereeachwordisavaliddictionaryword.Returnallsuchpossiblesentences.Forexample,givens="catsanddog",dict=["cat","cats","and","s
yoshino
·
2019-12-19 10:08
LeetCode每日一题
:不同的子序列数量
问题描述GivenastringSandastringT,countthenumberofdistinctsubsequencesofTinS.Asubsequenceofastringisanewstringwhichisformedfromtheoriginalstringbydeletingsome(canbenone)ofthecharacterswithoutdisturbingther
yoshino
·
2019-12-19 08:25
LeetCode每日一题
:二叉树的层序遍历
问题描述Givenabinarytree,returnthelevelordertraversalofitsnodes'values.(ie,fromlefttoright,levelbylevel).Forexample:Givenbinarytree{3,9,20,¥,¥,15,7},3/920/157returnitslevelordertraversalas:[[3],[9,20],[15
yoshino
·
2019-12-14 12:17
LeetCode每日一题
:integer to roman
问题描述Givenaninteger,convertittoaromannumeral.Inputisguaranteedtobewithintherangefrom1to3999.问题分析直接穷举即可,看代码就能明白。代码实现publicStringintToRoman(intnum){StringM[]={"","M","MM","MMM"};StringC[]={"","C","CC","C
yoshino
·
2019-12-13 21:08
LeetCode每日一题
:通过先序和中序建立二叉树
问题描述Givenpreorderandinordertraversalofatree,constructthebinarytree.Note:Youmayassumethatduplicatesdonotexistinthetree.问题分析和上一题类似,明白先序的第一个数就是根节点就好做了。代码实现publicTreeNodebuildTree(int[]preorder,int[]inord
yoshino
·
2019-12-13 18:46
LeetCode每日一题
:锯齿形输出二叉树的层序遍历
问题描述Givenabinarytree,returnthezigzaglevelordertraversalofitsnodes'values.(ie,fromlefttoright,thenrighttoleftforthenextlevelandalternatebetween).Forexample:Givenbinarytree{3,9,20,¥,¥,15,7},3/920/157ret
yoshino
·
2019-12-13 02:01
LeetCode每日一题
: 62. 不同路径
62.不同路径一个机器人位于一个mxn网格的左上角(起始点在下图中标记为“Start”)。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。问总共有多少条不同的路径?例如,上图是一个7x3的网格。有多少可能的路径?说明:m和n的值均不超过100。示例1:输入:m=3,n=2输出:3解释:从左上角开始,总共有3条路径可以到达右下角.向右->向右->向下
pao哥
·
2019-11-12 23:17
LeetCode每日一题
:reverse nodes in k group
问题描述Givenalinkedlist,reversethenodesofalinkedlistkatatimeandreturnitsmodifiedlist.Ifthenumberofnodesisnotamultipleofkthenleft-outnodesintheendshouldremainasitis.Youmaynotalterthevaluesinthenodes,onlyn
yoshino
·
2019-11-08 14:16
LeetCode每日一题
:three sum closest
问题描述GivenanarraySofnintegers,findthreeintegersinSsuchthatthesumisclosesttoagivennumber,target.Returnthesumofthethreeintegers.Youmayassumethateachinputwouldhaveexactlyonesolution.Forexample,givenarrayS
yoshino
·
2019-11-08 10:49
LeetCode每日一题
:merge two sorted lists
问题描述Mergetwosortedlinkedlistsandreturnitasanewlist.Thenewlistshouldbemadebysplicingtogetherthenodesofthefirsttwolists.问题分析很简单的链表操作题,注意保存好头结点指针和处理一个链表空了之后如何处理剩下的另一个链表代码实现publicListNodemergeTwoLists(Lis
yoshino
·
2019-11-08 03:10
LeetCode每日一题
:jump game ii
问题描述Givenanarrayofnon-negativeintegers,youareinitiallypositionedatthefirstindexofthearray.Eachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Yourgoalistoreachthelastindexintheminimumnu
yoshino
·
2019-11-07 22:30
LeetCode每日一题
:substring with concatenation of all words
问题描述Youaregivenastring,S,andalistofwords,L,thatareallofthesamelength.Findallstartingindicesofsubstring(s)inSthatisaconcatenationofeachwordinLexactlyonceandwithoutanyinterveningcharacters.Forexample,gi
yoshino
·
2019-11-06 01:26
LeetCode每日一题
:逆波兰式(后缀表达式)
问题描述EvaluatethevalueofanarithmeticexpressioninReversePolishNotation.Validoperatorsare+,-,,/.Eachoperandmaybeanintegeroranotherexpression.Someexamples:["2","1","+","3",""]->((2+1)*3)->9["4","13","5","/
yoshino
·
2019-11-04 04:35
LeetCode每日一题
:分割链表
问题描述Givenalinkedlistandavaluex,partitionitsuchthatallnodeslessthanxcomebeforenodesgreaterthanorequaltox.Youshouldpreservetheoriginalrelativeorderofthenodesineachofthetwopartitions.Forexample,Given1->4
yoshino
·
2019-11-03 06:56
LeetCode每日一题
:palindrome number
问题描述Determinewhetheranintegerisapalindrome.Dothiswithoutextraspace.clicktoshowspoilers.Somehints:Couldnegativeintegersbepalindromes?(ie,-1)Ifyouarethinkingofconvertingtheintegertostring,notetherestric
yoshino
·
2019-11-03 05:21
LeetCode每日一题
:归并两个有序数组
问题描述GiventwosortedintegerarraysAandB,mergeBintoAasonesortedarray.Note:YoumayassumethatAhasenoughspacetoholdadditionalelementsfromB.ThenumberofelementsinitializedinAandBaremandnrespectively.问题分析其实考察的是归
yoshino
·
2019-11-02 12:17
LeetCode每日一题
:独一的二叉搜索树 2
问题描述Givenn,generateallstructurallyuniqueBST's(binarysearchtrees)thatstorevalues1...n.Forexample,Givenn=3,yourprogramshouldreturnall5uniqueBST'sshownbelow.13321\///\321132//\2123问题分析和上一题类似,数量也是左子树和右子树的
yoshino
·
2019-11-01 08:35
LeetCode每日一题
:有效地回文串
问题描述Givenastring,determineifitisapalindrome,consideringonlyalphanumericcharactersandignoringcases.Forexample,"Aman,aplan,acanal:Panama"isapalindrome."raceacar"isnotapalindrome.Note:Haveyouconsiderthat
yoshino
·
2019-10-31 21:30
LeetCode每日一题
:环链表
问题描述Givenalinkedlist,returnthenodewherethecyclebegins.Ifthereisnocycle,returnnull.Followup:Canyousolveitwithoutusingextraspace?问题分析判断一个链表有没有环,只要判断快慢指针是否会相等即可。下面是快慢指针的一个性质:将两指针分别放在链表头(X)和相遇位置(Z),并改为相同速
yoshino
·
2019-10-31 19:37
LeetCode每日一题
:包围的XO
问题描述Givena2Dboardcontaining'X'and'O',captureallregionssurroundedby'X'.Aregioniscapturedbyflippingall'O'sinto'X'sinthatsurroundedregion.Forexample,XXXXXOOXXXOXXOXXAfterrunningyourfunction,theboardshoul
yoshino
·
2019-10-31 06:47
Leetcode每日一题
——回文数
题目判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。链接:回文数.示例示例1:输入:121输出:true示例2:输入:-121输出:false解释:从左向右读,为-121。从右向左读,为121-。因此它不是一个回文数。示例3:输入:10输出:false解释:从右向左读,为01。因此它不是一个回文数。解题过程作为一名小菜鸡,我终于想起来这些题目我好像大二考CC
hnucs
·
2019-10-11 11:12
Leetcode刷题
Leetcode
Leetcode每日一题
-两数之和
1、两数之和暴力解classSolution{public:vectortwoSum(vector&nums,inttarget){inti,j;for(i=0;itwoSum(vector&nums,inttarget){inti,j;for(i=1;itwoSum(vector&nums,inttarget){vectorres;unordered_maphash;for(inti=0;i({
loserChen.
·
2019-09-04 19:56
leetcode
LeetCode每日一题
——T21. 合并两个有序链表(易):链表,递归 / 迭代
法一:递归classSolution:defmergeTwoLists(self,l1:ListNode,l2:ListNode)->ListNode:ifl1isNone:returnl2elifl2isNone:returnl1elifl1.valListNode:res_head=ListNode(-2)#因为链表无头节点,所以自己创建头节点,其中-2无任何意义;头结点-->next指向第一
同濟伴讀書僮
·
2019-07-19 14:09
代码
leetcode
每日一题T21.
合并两个有序链表
python
LeetCode每日一题
——T4. 寻找两个有序数组的中位数(难):递归、二分索引
代码及思路来源:https://blog.csdn.net/LoveHYZH/article/details/92760709博主在分类时的表格十分好,让人一目了然,借鉴展示如下(侵删):classSolution:deffindMedianSortedArrays(self,nums1:List[int],nums2:List[int])->float:m,n=len(nums1),len(nu
同濟伴讀書僮
·
2019-06-28 21:48
代码
leetcode每日一题
T4.
寻找两个有序数组的中位数
python
LeetCode每日一题
:数组拆分 I(No.561)
题目:数组拆分I给定长度为2n的数组,你的任务是将这些数分成n对,例如(a1,b1),(a2,b2),...,(an,bn),使得从1到n的min(ai,bi)总和最大。复制代码示例:输入:[1,4,3,2]输出:4解释:n等于2,最大总和为4=min(1,2)+min(3,4).复制代码思考:这道题先将数组排序,再从下标0开始,间隔相加,即为结果。复制代码实现:classSolution{pub
weixin_34041003
·
2019-06-06 02:30
数据结构与算法
LeetCode每日一题
14. 最接近的三数之和
LeetCode题目给定一个包括n个整数的数组nums和一个目标值target。找出nums中的三个整数,使得它们的和与target最接近。返回这三个数的和。假定每组输入只存在唯一答案。例如,给定数组nums=[-1,2,1,-4],和target=1.与target最接近的三个数的和为2.(-1+2+1=2).分析这是一道中等难度的题,是之前三数之和的变种,条件复杂了一些,但总体的思路没有变化.
FesonX
·
2019-05-05 09:00
LeetCode每日一题
: 数组形式的整数加法(No.989)
题目:数组形式的整数加法对于非负整数X而言,X的数组形式是每位数字按从左到右的顺序形成的数组。例如,如果X=1231,那么其数组形式为[1,2,3,1]。给定非负整数X的数组形式A,返回整数X+K的数组形式。复制代码示例:输入:A=[1,2,0,0],K=34输出:[1,2,3,4]解释:1200+34=1234输入:A=[2,7,4],K=181输出:[4,5,5]解释:274+181=455输
weixin_33725807
·
2019-04-24 05:07
数据结构与算法
leetcode每日一题
之30.Substring with Concatenation of All Words
题目描述:与所有单词相关联的子串给定一个子串s和一些长度相同的单词组成的字符串数组words.注意:在s中找出恰好串联words中所有单词的子串的起始位置,中间不能有其他字符,但不要考虑words中单词串联的顺序.示例1:(允许无序)Input:s=“barfoothefoobarman”,words=[“foo”,“bar”]Output:[0,9]示例2:(中间不能有其他字符)Input:s=
weixin_43874501
·
2019-04-08 17:18
leetcode
算法
leetcode
LeetCode每日一题
122: 买卖股票的最佳时机 II
leetcode.png题目给定一个数组,它的第i个元素是一支给定股票第i天的价格。设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。示例1:输入:[7,1,5,3,6,4]输出:7解释:在第2天(股票价格=1)的时候买入,在第3天(股票价格=5)的时候卖出,这笔交易所能获得利润=5-1=4
FesonX
·
2019-02-22 23:12
LeetCode每日一题
14. 最长公共前缀
LeetCode题目编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串""。示例1:输入:["flower","flow","flight"]输出:"fl"示例2:输入:["dog","racecar","car"]输出:""解释:输入不存在公共前缀。说明:所有输入只包含小写字母a-z。分析做这种题对新手最不友好的是用例覆盖问题,很多时候提交了发现这个用例不行那个又行,
FesonX
·
2019-02-21 16:00
数据结构
LeetCode
算法
算法与数据结构
LeetCode每日一题
:zigzag conversion
问题描述Thestring"PAYPALISHIRING"iswritteninazigzagpatternonagivennumberofrowslikethis:(youmaywanttodisplaythispatterninafixedfontforbetterlegibility)PAHNAPLSIIGYIRAndthenreadlinebyline:"PAHNAPLSIIGYIR"Wr
yoshino
·
2017-07-06 09:41
LeetCode每日一题
:search for a range
问题描述Givenasortedarrayofintegers,findthestartingandendingpositionofagiventargetvalue.Youralgorithm'sruntimecomplexitymustbeintheorderofO(logn).Ifthetargetisnotfoundinthearray,return[-1,-1].Forexample,G
yoshino
·
2017-06-29 10:11
LeetCode每日一题
:rotate image
问题描述Youaregivenannxn2Dmatrixrepresentinganimage.Rotatetheimageby90degrees(clockwise).Followup:Couldyoudothisin-place?问题分析顺时针旋转矩阵90度,使用替换而不是新建新的矩阵。代码实现publicvoidrotate(int[][]matrix){intn=matrix.length
yoshino
·
2017-06-16 14:58
LeetCode每日一题
:n queens ii
问题描述FollowupforN-Queensproblem.Now,insteadoutputtingboardconfigurations,returnthetotalnumberofdistinctsolutions.问题分析和上一题类似,只是输出改成了结果数量,其实比上一题简单。代码实现privatebooleancheck(introw,int[]columnForRow){for(in
yoshino
·
2017-06-14 15:47
LeetCode每日一题
:insert interval
问题描述Givenasetofnon-overlappingintervals,insertanewintervalintotheintervals(mergeifnecessary).Youmayassumethattheintervalswereinitiallysortedaccordingtotheirstarttimes.Example1:Givenintervals[1,3],[6,9
yoshino
·
2017-06-07 17:18
LeetCode每日一题
:unique paths
问题描述Arobotislocatedatthetop-leftcornerofamxngrid(marked'Start'inthediagrambelow).Therobotcanonlymoveeitherdownorrightatanypointintime.Therobotistryingtoreachthebottom-rightcornerofthegrid(marked'Finis
yoshino
·
2017-06-02 10:19
上一页
27
28
29
30
31
32
33
34
下一页
按字母分类:
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
其他