javaclassSolution{publicStringremoveOuterParentheses(Strings){StringBufferres=newStringBuffer();Deque<Characterstack=newArrayDeque<Character();for(inti=0;i<s.length();i){charc=s.charAt(i);if(c')'){sta
javaclassSolution{publicintfindClosest(Stringwords,Stringword1,Stringword2){intn=words.length;intres=n;for(inti=0,a=1,b=1;i<n;i){if(wordsi.equals(word1)){a=i;}if(wordsi.equals(word2)){b=i;}if(a!=1&&b!
javaclassSolution{publicintfindSubstringInWraproundString(Stringp){intdp=newint26;intk=0;//目前连续递增的字串长度for(inti=0;i<p.length();i){if(i0&&((p.charAt(i)p.charAt(i1)+26)%261)){//跟前一个字符相邻:字符之差为1或25k;}else{
https://leetcode.cn/problems/univaluedbinarytree/(https://leetcode.cn/problems/univaluedbinarytree/)java/Definitionforabinarytreenode.publicclassTreeNode{intval;TreeNodeleft;TreeNoderight;TreeNode(){}
https://leetcode.cn/problems/cutofftreesforgolfevent/(https://leetcode.cn/problems/cutofftreesforgolfevent/)javaclassSolution{//你需要按照树的高度从低向高砍掉所有的树publicintcutOffTree(List<List<Integerforest){ArrayLis
题目https://leetcode.cn/problems/caniwin/(https://leetcode.cn/problems/caniwin/)本题是一道记忆化搜索题。此类题型我不会做,今后还需加强。状态压缩采用二进制的方式,将i的状态保存在usedNumbers的第i位。判断有无用过:看usedNumbers的第i位是否为1标记已经用过:将usedNumbers的第i位设为1代码ja
javaclassSolution{publicintrepeatedNTimes(intnums){intlen=nums.length;intn=len/2;for(inti=1;i<=3;i){for(intj=0;j+i<len;j){if(numsjnumsj+i){returnnumsj;}}}return1;}}
https://leetcode.cn/problems/findrightinterval/(https://leetcode.cn/problems/findrightinterval/)javaclassSolution{publicintfindRightInterval(intintervals){intn=intervals.length;intstartIntervals=newin
https://leetcode.cn/problems/minimummovestoequalarrayelementsii/(https://leetcode.cn/problems/minimummovestoequalarrayelementsii/)javaclassSolution{publicintminMoves2(intnums){intn=nums.length;if(n1)r
卢梭曾经说过:“人生而自由,又不往在枷锁中。”但我仍要说:不自由,毋宁死。二分查找https://leetcode.cn/problems/kthsmallestnumberinmultiplicationtable/(https://leetcode.cn/problems/kthsmallestnumberinmultiplicationtable/)javaclassSolution{pub
https://leetcode.cn/problems/verifyinganaliendictionary/(https://leetcode.cn/problems/verifyinganaliendictionary/)javaclassSolution{publicbooleanisAlienSorted(Stringwords,Stringorder){HashMap<Characte
题目https://leetcode.cn/problems/successorlcci/(https://leetcode.cn/problems/successorlcci/)代码效率很低的,将中序遍历的结果保存,然后取p的下一个java/Definitionforabinarytreenode.publicclassTreeNode{intval;TreeNodeleft;TreeNoder
题目https://leetcode.cn/problems/largesttrianglearea/(https://leetcode.cn/problems/largesttrianglearea/)分析三角形的面积公式:1/2∗x1(y2−y3)+x2(y3−y1)+x3(y1−y2)说实话我真不知道这个公式,我好没文化代码javaclassSolution{publicdoublelarg
https://leetcode.cn/problems/ransomnote/(https://leetcode.cn/problems/ransomnote/)javaclassSolution{publicbooleancanConstruct(StringransomNote,Stringmagazine){intcount=newint26;for(charc:magazine.toCh
题目链接https://leetcode.cn/problems/oneawaylcci/(https://leetcode.cn/problems/oneawaylcci/)代码javaclassSolution{publicbooleanoneEditAway(Stringfirst,Stringsecond){if(first.equals(second)){//完全相同0次returntr
https://leetcode.cn/problems/deletecolumnstomakesorted/(https://leetcode.cn/problems/deletecolumnstomakesorted/)javaclassSolution{publicintminDeletionSize(Stringstrs){intm=strs.length;intn=strs0.lengt
https://leetcode.cn/problems/serializeanddeserializebst/(https://leetcode.cn/problems/serializeanddeserializebst/)javapublicclassCodec{//序列化publicStringserialize(TreeNoderoot){List<Integerlist=newArra
2264javaclassSolution{publicStringlargestGoodInteger(Stringnum){intn=num.length();charmax='';for(inti=0;i<n2;i){if(num.charAt(i)num.charAt(i+1)&&num.charAt(i+1)num.charAt(i+2)){if(max!=''){if(num.char
https://leetcode.cn/problems/distringmatch/(https://leetcode.cn/problems/distringmatch/)javaclassSolution{publicintdiStringMatch(Strings){intn=s.length();intres=newintn+1;intlow=0,high=n;for(inti=0;i<
javaclassSolution{publicList<IntegerfindDuplicates(intnums){intn=nums.length;ArrayList<Integerres=newArrayList<();intcount=newintn+1;for(intnum:nums){countnum;if(countnum2){res.add(num);}}returnres;}}
题目https://leetcodecn.com/problems/numberofrecentcalls/(https://leetcodecn.com/problems/numberofrecentcalls/)代码javaclassRecentCounter{Deque<Integerqueue;publicRecentCounter(){queue=newArrayDeque<();}pu
题目https://leetcodecn.com/problems/subarrayproductlessthank/(https://leetcodecn.com/problems/subarrayproductlessthank/)滑动窗口javaclassSolution{publicintnumSubarrayProductLessThanK(intnums,intk){intres=0;
题目https://leetcodecn.com/problems/findthewinnerofthecirculargame/(https://leetcodecn.com/problems/findthewinnerofthecirculargame/)模拟javaclassSolution{publicintfindTheWinner(intn,intk){Queue<Integerque
https://leetcodecn.com/problems/reorderdatainlogfiles/(https://leetcodecn.com/problems/reorderdatainlogfiles/)javaclassSolution{publicStringreorderLogFiles(Stringlogs){Pairpairs=newPairlogs.length;for
题目https://leetcodecn.com/problems/smallestrangei/(https://leetcodecn.com/problems/smallestrangei/)分析ma为最大值,mi为最小值。x为ma修改时加的数,y为mi修改时加的数。修改后的差值=(ma+x)(mi+y)=(mami)+(xy)x,y属于k,k(xy)范围2k,2kxy=mima时,左式为0,
题目https://leetcodecn.com/problems/sortarraybyparity/(https://leetcodecn.com/problems/sortarraybyparity/)方法利用双指针。目的是让a指向奇数,b指向偶数,交换。代码javaclassSolution{publicintsortArrayByParity(intnums){intn=nums.len
题目(https://leetcodecn.com/problems/pacificatlanticwaterflow/)从边界(可入海地带)出发,向内陆方向前进,反向获取答案。javaclassSolution{intdirs={{0,1},{0,1},{1,0},{1,0}};intheights;intm,n;publicList<List<IntegerpacificAtlantic(in
https://leetcodecn.com/problems/projectionareaof3dshapes/(https://leetcodecn.com/problems/projectionareaof3dshapes/)javaclassSolution{publicintprojectionArea(intgrid){//yz平面的投影面积等于网格上每一列最大数值之和;//xz平面的
https://leetcodecn.com/problems/randompickindex/(https://leetcodecn.com/problems/randompickindex/)javaclassSolution{intnums;publicSolution(intnums){this.nums=nums;}publicintpick(inttarget){intcount=0;
https://leetcodecn.com/problems/binarygap/(https://leetcodecn.com/problems/binarygap/)javaclassSolution{publicintbinaryGap(intn){intcount=0;intfirst=0,second=0;intres=0;while(n!=0){count;if((n&1)1){if
Copyright © 2005-2024 51CTO.COM 版权所有 京ICP证060544号