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每日一题
(1111. 有效括号的嵌套深度)
1111.有效括号的嵌套深度前言首先,做这道题的时候,我们先来温习一下(20.有效的括号)这道题。本题借助了辅助栈,也就是使用了栈操作方式。也算是再算法题中最基本的数据结构算法题1.题目给定一个只包括‘(’,’)’,’{’,’}’,’[’,’]’的字符串,判断字符串是否有效。有效字符串需满足:左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。注意空字符串可被认为是有效字符串。示例1:输
月半的美男子
·
2020-04-01 16:04
java
字符串
数据结构
java
算法
LeetCode每日一题
:generate parentheses
问题描述Givennpairsofparentheses,writeafunctiontogenerateallcombinationsofwell-formedparentheses.Forexample,givenn=3,asolutionsetis:"((()))","(()())","(())()","()(())","()()()"问题分析遇到要列出所有情况的问题直接使用递归,用left
yoshino
·
2020-03-30 21:19
LeetCode每日一题
:独一的二叉搜索树 1
问题描述Givenn,howmanystructurallyuniqueBST's(binarysearchtrees)thatstorevalues1...n?Forexample,Givenn=3,thereareatotalof5uniqueBST's.13321\///\321132//\2123问题分析求一共有多少种二叉搜索树,我们可以求一个节点的左右子树各有多少个,把他们相乘起来就是有
yoshino
·
2020-03-27 16:38
LeetCode每日一题
:combinations
问题描述Giventwointegersnandk,returnallpossiblecombinationsofknumbersoutof1...n.Forexample,Ifn=4andk=2,asolutionis:[[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]问题分析这题不能直接穷举,有k层循环会直接超时的,我们可以采用dfs来遍历,用depth来表示第一个数
yoshino
·
2020-03-27 07:36
LeetCode每日一题
:letter combination of a phone number
问题描述Givenadigitstring,returnallpossiblelettercombinationsthatthenumbercouldrepresent.Amappingofdigittoletters(justlikeonthetelephonebuttons)isgivenbelow.Input:Digitstring"23"Output:["ad","ae","af","bd
yoshino
·
2020-03-24 22:15
LeetCode每日一题
:两数之和
题目:给定一个整数数组nums和一个目标值target,请你在该数组中找出和为目标值的那两个整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。示例:给定nums=[2,7,11,15],target=9因为nums[0]+nums[1]=2+7=9所以返回[0,1]方法一:暴力法遍历每一个元素,求他们相加的值等于目标值实现代码:classSo
不会Java怎么找女朋友
·
2020-03-24 14:59
LeetCode
LeetCode每日一题
:二叉树路径和 1
问题描述Givenabinarytreeandasum,determineifthetreehasaroot-to-leafpathsuchthataddingupallthevaluesalongthepathequalsthegivensum.Forexample:Giventhebelowbinarytreeandsum=22,5/48//11134/\721returntrue,asthe
yoshino
·
2020-03-24 03:17
leetcode每日一题
python解法 3月24日
难度:简单题目内容:一个有名的按摩师会收到源源不断的预约请求,每个预约都可以选择接或不接。在每次预约服务之间要有休息时间,因此她不能接受相邻的预约。给定一个预约请求序列,替按摩师找到最优的预约集合(总预约时间最长),返回总的分钟数。注意:本题相对原题稍作改动示例1:输入:[1,2,3,1]输出:4解释:选择1号预约和3号预约,总时长=1+3=4。示例2:输入:[2,7,9,3,1]输出:12解释:
Never肥宅
·
2020-03-24 01:59
LeetCode每日一题
:remove duplicates from sorted array i
问题描述Givenasortedarray,removetheduplicatesinplacesuchthateachelementappearonlyonceandreturnthenewlength.Donotallocateextraspaceforanotherarray,youmustdothisinplacewithconstantmemory.Forexample,Giveninp
yoshino
·
2020-03-23 21:57
LeetCode每日一题
:search in rotated sorted array i
问题描述Supposeasortedarrayisrotatedatsomepivotunknowntoyoubeforehand.(i.e.,0124567mightbecome4567012).Youaregivenatargetvaluetosearch.Iffoundinthearrayreturnitsindex,otherwisereturn-1.Youmayassumenodupli
yoshino
·
2020-03-20 19:34
LeetCode每日一题
:sudoku solver
问题描述WriteaprogramtosolveaSudokupuzzlebyfillingtheemptycells.Emptycellsareindicatedbythecharacter'.'.Youmayassumethattherewillbeonlyoneuniquesolution.问题分析和上一题不同,不仅要判断数独是否合法,还必须给出一种解法,采用dfs算法即可。代码实现publ
yoshino
·
2020-03-20 15:32
LeetCode每日一题
:remove duplicates from sorted list i
问题描述Givenasortedlinkedlist,deleteallduplicatessuchthateachelementappearonlyonce.Forexample,Given1->1->2,return1->2.Given1->1->2->3->3,return1->2->3.问题分析删除链表中的重复节点,链表中很常见的操作,Java不需要考虑释放结点,而C++必须删除无用节点代
yoshino
·
2020-03-19 05:12
LeetCode每日一题
:combination sum i
问题描述Givenasetofcandidatenumbers(C)andatargetnumber(T),findalluniquecombinationsinCwherethecandidatenumberssumstoT.ThesamerepeatednumbermaybechosenfromCunlimitednumberoftimes.Note:Allnumbers(includingt
yoshino
·
2020-03-18 22:02
LeetCode每日一题
:permutations ii
问题描述Givenacollectionofnumbersthatmightcontainduplicates,returnallpossibleuniquepermutations.Forexample,[1,1,2]havethefollowinguniquepermutations:[1,1,2],[1,2,1],and[2,1,1].问题分析这题和上题类似,本想直接套用上题的代码再用set
yoshino
·
2020-03-18 02:17
leetcode每日一题
MergeSortedArrayQuestionleetcode:MergeSortedArray|LeetCodeOJlintcode:(6)MergeSortedArrayGiventwosortedintegerarraysAandB,mergeBintoAasonesortedarray.ExampleA=[1,2,3,empty,empty],B=[4,5]Aftermerge,Awil
Sidney001
·
2020-03-17 23:20
LeetCode每日一题
:unique paths ii
问题描述Followupfor"UniquePaths":Nowconsiderifsomeobstaclesareaddedtothegrids.Howmanyuniquepathswouldtherebe?Anobstacleandemptyspaceismarkedas1and0respectivelyinthegrid.Forexample,Thereisoneobstacleinthem
yoshino
·
2020-03-16 22:36
LeetCode每日一题
:判断两棵树是否相同
问题描述Giventwobinarytrees,writeafunctiontocheckiftheyareequalornot.Twobinarytreesareconsideredequaliftheyarestructurallyidenticalandthenodeshavethesamevalue.问题分析判断两棵树是否相同,只需要递归判断每个点的左右孩子是否相同就行了代码实现publi
yoshino
·
2020-03-16 13:55
LeetCode每日一题
:valid sudoku
问题描述DetermineifaSudokuisvalid,accordingto:SudokuPuzzles-TheRules.TheSudokuboardcouldbepartiallyfilled,whereemptycellsarefilledwiththecharacter'.'.问题分析判断数独是否合法,数独只需要满足每个小的九宫格里面的每一行每一列里1-9只出现一次,直接暴力求解即可
yoshino
·
2020-03-15 19:46
LeetCode每日一题
:longest palindromic substring
问题描述GivenastringS,findthelongestpalindromicsubstringinS.YoumayassumethatthemaximumlengthofSis1000,andthereexistsoneuniquelongestpalindromicsubstring.问题分析我们可以采用递归的方式,找每个字符为中心的最长回文子串,用一个全局变量(写代码应该尽量避免全局
yoshino
·
2020-03-15 06:12
LeetCode每日一题
:merge intervals
问题描述Givenacollectionofintervals,mergealloverlappingintervals.Forexample,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].问题分析合并有重叠的分区,首先根据start进行排序,把第一个区间存入结果中,然后从第二个开始遍历区间集,如果结果中最后一个区间和遍历的当
yoshino
·
2020-03-15 04:54
LeetCode每日一题
:回文字符串 2
问题描述Givenastrings,partitionssuchthateverysubstringofthepartitionisapalindrome.Returntheminimumcutsneededforapalindromepartitioningofs.Forexample,givens="aab",Return1sincethepalindromepartitioning["aa"
yoshino
·
2020-03-14 21:56
LeetCode每日一题
:longest common prefix
问题描述Writeafunctiontofindthelongestcommonprefixstringamongstanarrayofstrings.问题分析这道题本来想用动态规划来做的,但是直接暴力求解也很方便,因为最长公共前缀的距离肯定是越来越短的,直接一一比较过去即可。代码实现publicStringlongestCommonPrefix(String[]strs){if(strs.len
yoshino
·
2020-03-14 19:06
LeetCode每日一题
:子集 2
问题描述Givenacollectionofintegersthatmightcontainduplicates,S,returnallpossiblesubsets.Note:Elementsinasubsetmustbeinnon-descendingorder.Thesolutionsetmustnotcontainduplicatesubsets.Forexample,IfS=[1,2,2
yoshino
·
2020-03-14 15:38
LeetCode每日一题
:jump game i
问题描述Givenanarrayofnon-negativeintegers,youareinitiallypositionedatthefirstindexofthearray.Eachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Determineifyouareabletoreachthelastindex.Fo
yoshino
·
2020-03-14 07:10
LeetCode每日一题
:remove element
问题描述Givenanarrayandavalue,removeallinstancesofthatvalueinplaceandreturnthenewlength.Theorderofelementscanbechanged.Itdoesn'tmatterwhatyouleavebeyondthenewlength.问题分析这题让我们移除重复元素,说好的顺序可以无所谓,但实际通过不了AC。代码
yoshino
·
2020-03-14 05:17
leetcode每日一题
:(6)ZigZag Conversion
ZigZagConversionQuestionleetcode:ZigZagConversion|LeetCodeOJThestring"PAYPALISHIRING"iswritteninazigzagpatternonagivennumberofrowslikethis:(youmaywanttodisplaythispatterninafixedfontforbetterlegibilit
Sidney001
·
2020-03-12 13:30
LeetCode每日一题
:permutations
问题描述Givenacollectionofnumbers,returnallpossiblepermutations.Forexample,[1,2,3]havethefollowingpermutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],and[3,2,1].问题分析数组全排列问题,典型的递归算法,每次交换两位数字递归生成所有的数组就行了。代
yoshino
·
2020-03-10 00:58
LeetCode每日一题
:填充next指针指向右边节点 2
问题描述Followupforproblem"PopulatingNextRightPointersinEachNode".Whatifthegiventreecouldbeanybinarytree?Wouldyourprevioussolutionstillwork?Note:Youmayonlyuseconstantextraspace.Forexample,Giventhefollowin
yoshino
·
2020-03-08 05:52
LeetCode每日一题
:merge k sorted list
问题描述Mergeksortedlinkedlistsandreturnitasonesortedlist.Analyzeanddescribeitscomplexity.问题分析我们可以使用以前写过的合并两条有序链表mergeTwoLists()函数,循环k次即可,复杂度是O(n*k)=O(n^2)。代码实现publicListNodemergeKLists(ArrayListlists){if
yoshino
·
2020-03-07 13:21
LeetCode每日一题
:三数之和
题目:给定一个包含n个整数的数组nums,判断nums中是否存在三个元素a,b,c,使得a+b+c=0?找出所有满足条件且不重复的三元组。注意:答案中不可以包含重复的三元组。示例:给定数组nums=[-1,0,1,2,-1,-4],满足要求的三元组集合为:[[-1,0,1],[-1,-1,2]]思路:本文提供的排序+双指针思路1.对数组进行升序排序。2.对于数组中任意一个值,假设其索引为k,len
qq_40053995
·
2020-03-06 15:21
leetcode
java
LeetCode每日一题
:n queens i
问题描述Then-queenspuzzleistheproblemofplacingnqueensonann×nchessboardsuchthatnotwoqueensattackeachother.Givenanintegern,returnalldistinctsolutionstothen-queenspuzzle.Eachsolutioncontainsadistinctboardcon
yoshino
·
2020-03-04 03:38
LeetCode每日一题
:单词梯 2
问题描述Giventwowords(startandend),andadictionary,findallshortesttransformationsequence(s)fromstarttoend,suchthat:OnlyonelettercanbechangedatatimeEachintermediatewordmustexistinthedictionaryForexample,Giv
yoshino
·
2020-03-02 08:28
LeetCode每日一题
:multiply strings
问题描述Giventwonumbersrepresentedasstrings,returnmultiplicationofthenumbersasastring.Note:Thenumberscanbearbitrarilylargeandarenon-negative.问题分析这题简直就是为java设计的,用C++的话还要考虑转化和进位,在java只需要用BigDecimal进行大数精确运算即
yoshino
·
2020-03-02 07:44
LeetCode每日一题
:二叉树路径和 2
问题描述Givenabinarytreeandasum,findallroot-to-leafpathswhereeachpath'ssumequalsthegivensum.Forexample:Giventhebelowbinarytreeandsum=22,5/48//11134/\/7251return[[5,4,11,2],[5,8,4,5]]问题分析和上题一样,采用递归就可以了,但是要
yoshino
·
2020-03-01 08:55
LeetCode每日一题
:search a 2d matrix
问题描述Writeanefficientalgorithmthatsearchesforavalueinanmxnmatrix.Thismatrixhasthefollowingproperties:Integersineachrowaresortedfromlefttoright.Thefirstintegerofeachrowisgreaterthanthelastintegerofthepr
yoshino
·
2020-03-01 04:41
LeetCode每日一题
:二叉树后序遍历
问题描述Givenabinarytree,returnthepostordertraversalofitsnodes'values.Forexample:Givenbinarytree{1,#,2,3},12/3return[3,2,1].Note:Recursivesolutionistrivial,couldyoudoititeratively?问题分析考察二叉树的后序遍历(左右根),不用递归
yoshino
·
2020-02-29 23:32
LeetCode每日一题
:记录链表
问题描述GivenasinglylinkedlistL:L0→L1→…→Ln-1→Ln,reorderitto:L0→Ln→L1→Ln-1→L2→Ln-2→…Youmustdothisin-placewithoutalteringthenodes'values.Forexample,Given{1,2,3,4},reorderitto{1,4,2,3}.问题分析此题是要将链表后半段逆转,之后再插入
yoshino
·
2020-02-29 04:36
LeetCode每日一题
236. 二叉树的最近公共祖先
leetcode.png题目给定一个二叉树,找到该树中两个指定节点的最近公共祖先。百度百科中最近公共祖先的定义为:“对于有根树T的两个结点p、q,最近公共祖先表示为一个结点x,满足x是p、q的祖先且x的深度尽可能大(一个节点也可以是它自己的祖先)。”例如,给定如下二叉树:root=[3,5,1,6,2,0,8,null,null,7,4]image示例1:输入:root=[3,5,1,6,2,0,
FesonX
·
2020-02-26 18:59
LeetCode每日一题
:解码的方法数
问题描述AmessagecontaininglettersfromA-Zisbeingencodedtonumbersusingthefollowingmapping:'A'->1'B'->2...'Z'->26Givenanencodedmessagecontainingdigits,determinethetotalnumberofwaystodecodeit.Forexample,Given
yoshino
·
2020-02-24 07:34
LeetCode每日一题
:pow(x,n)
问题描述Implementpow(x,n).问题分析这一题让我们模拟pow(x,n)函数,下面提供一种二分的方法,时间复杂度为O(logn)代码实现publicdoublepow(doublex,intn){if(n==0)return1.0;doublehalf=pow(x,n/2);if(n%2==0){returnhalf*half;}elseif(n>0){returnhalf*half*
yoshino
·
2020-02-23 08:41
LeetCode每日一题
:单词梯 1
问题描述Giventwowords(startandend),andadictionary,findthelengthofshortesttransformationsequencefromstarttoend,suchthat:OnlyonelettercanbechangedatatimeEachintermediatewordmustexistinthedictionaryForexampl
yoshino
·
2020-02-22 23:29
LeetCode每日一题
:spiral matrix ii
问题描述Givenanintegern,generateasquarematrixfilledwithelementsfrom1ton2inspiralorder.Forexample,Givenn=3,Youshouldreturnthefollowingmatrix:[[1,2,3],[8,9,4],[7,6,5]]问题分析和上题类似,只需要按照便利顺序一层层地添加就好了。代码实现public
yoshino
·
2020-02-22 17:47
LeetCode每日一题
:二叉树中序排列
问题描述Givenabinarytree,returntheinordertraversalofitsnodes'values.Forexample:Givenbinarytree{1,#,2,3},12/3return[1,3,2].Note:Recursivesolutionistrivial,couldyoudoititeratively?问题分析二叉树的中序排列,用递归比较简便,题目要求用
yoshino
·
2020-02-22 11:31
LeetCode每日一题
:修复二叉搜索树
问题描述Twoelementsofabinarysearchtree(BST)areswappedbymistake.Recoverthetreewithoutchangingits问题分析我们注意到二叉搜索树的中序排列是一个递增的数,我们只要把他的中序上大小错误的点交换,重新改成中序排列的就行了代码实现publicvoidrecoverTree(TreeNoderoot){ArrayListli
yoshino
·
2020-02-22 04:12
LeetCode每日一题
:分词1
问题描述Givenastringsandadictionaryofwordsdict,determineifscanbesegmentedintoaspace-separatedsequenceofoneormoredictionarywords.Forexample,givens="leetcode",dict=["leet","code"].Returntruebecause"leetcode
yoshino
·
2020-02-21 18:53
LeetCode每日一题
:four sum
问题描述GivenanarraySofnintegers,arethereelementsa,b,c,anddinSsuchthata+b+c+d=target?Findalluniquequadrupletsinthearraywhichgivesthesumoftarget.Note:Elementsinaquadruplet(a,b,c,d)mustbeinnon-descendingord
yoshino
·
2020-02-21 15:36
LeetCode每日一题
:买卖股票的最好时机 3
问题描述Sayyouhaveanarrayforwhichtheielementisthepriceofagivenstockondayi.Designanalgorithmtofindthemaximumprofit.Youmaycompleteatmosttwotransactions.Note:Youmaynotengageinmultipletransactionsatthesametim
yoshino
·
2020-02-18 09:16
LeetCode每日一题
:帕斯卡三角(杨辉三角) 2
问题描述Givenanindexk,returnthekthrowofthePascal'striangle.Forexample,givenk=3,Return[1,3,3,1].Note:CouldyouoptimizeyouralgorithmtouseonlyO(k)extraspace?问题分析这题是打印某一层的值,直接改动一下上一题的返回值即可。这样虽然能够AC,但是不符合只使用O(k
yoshino
·
2020-02-17 04:38
LeetCode每日一题
:two sum
问题描述Givenanarrayofintegers,findtwonumberssuchthattheyadduptoaspecifictargetnumber.ThefunctiontwoSumshouldreturnindicesofthetwonumberssuchthattheyadduptothetarget,whereindex1mustbelessthanindex2.Please
yoshino
·
2020-02-15 21:04
LeetCode每日一题
:sqrtx
问题描述Implementintsqrt(intx).Computeandreturnthesquarerootofx.问题分析这道题目直接调用Math.sqrt(x)也可以AC,但是我们最好用二分查找或者牛顿迭代法来进行查找。牛顿迭代法是通过切线来确定根的位置,通过无限趋近的极限思想来找平方根,证明省略,我们直接使用结论。x[i+1]=x[i]/2+n/(2*x[i]);当x[i+1]趋近于x[
yoshino
·
2020-02-15 08:24
上一页
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
其他