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题解
:MinStack(三种解法)
Designastackthatsupportspush,pop,top,andretrievingtheminimumelementinconstanttime.push(x)--Pushelementxontostack.pop()--Removestheelementontopofthestack.top()--Getthetopelement.getMin()--Retrievethemi
u012403246
·
2014-11-18 10:00
LeetCode题解
:Symmetric Tree(有4种解法)
Givenabinarytree,checkwhetheritisamirrorofitself(ie,symmetricarounditscenter).Forexample,thisbinarytreeissymmetric:1 /\ 22 /\/\ 3443 Butthefollowingisnot:1 /\ 22 \\ 33 题解:判断一棵二叉树是否是自身的镜像,即:一棵爱美的二叉树去照镜
u012403246
·
2014-11-17 19:00
LeetCode题解
:Count and Say解法
Thecount-and-saysequenceisthesequenceofintegersbeginningasfollows:1,11,21,1211,111221,...1 isreadoffas "one1" or 11.11 isreadoffas "two1s" or 21.21 isreadoffas "one2,then one1" or 1211.Givenaninteger
u012403246
·
2014-11-16 22:00
LeetCode题解
:Single Number最优解法
Givenanarrayofintegers,everyelementappears twice exceptforone.Findthatsingleone.Note:Youralgorithmshouldhavealinearruntimecomplexity.Couldyouimplementitwithoutusingextramemory?题目大意:一个整数数组中,除了一个数只出现了一次
u012403246
·
2014-11-16 19:00
LeetCode题解
——Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:
Mir_Tempo
·
2014-08-23 14:00
java
算法
HDU 1027 Ignatius and the Princess II 选择序列题解
如何直接选择第k个序列,可以参考本博客的
Leetcode题解
。Leetcode题有个一模一样的题目。不过没有使
kenden23
·
2014-08-20 08:00
LeetCode题解
汇总(C++ Java Python,含题目翻译)
更多代码请见我的github:https://github.com/lilong-dream/本文同时发布在我的个人网站,欢迎访问:http://www.lilongdream.com/2014/04/08/30.htmlLeetCode题目(含ACRates):http://oj.leetcode.com/problems/题目难度分布、面试频率及使用的数据结构与算法分析:http://blog
lilong_dream
·
2014-02-23 17:09
LeetCode
[置顶] 索(shen)引(keng)大全
计算机网络_学习笔记索引「索引」《Python基础教程》学习笔记XMLFromActionScript[AS中的XML学习笔记]《算法导论》习题解答搬运&&学习笔记索引目录)(已废) [LeetCode]
Leetcode
hcbbt
·
2014-01-23 11:00
索引
LeetCode题解
:Candy
CandyThereareNchildrenstandinginaline.Eachchildisassignedaratingvalue.Youaregivingcandiestothesechildrensubjectedtothefollowingrequirements:Eachchildmusthaveatleastonecandy.Childrenwithahigherratingge
MagiSu
·
2014-01-07 14:00
LeetCode
LeetCode总结
除各个题目有特殊巧妙的解法以外,大部分题目都是经典的算法或者数据结构,因此做了如下小结,具体的解题思路可以搜索我的博客:
LeetCode题解
题目算法数据结构注意事项CloneGraphBFS哈希表WordLadderIIBFS
Allanxl
·
2014-01-04 20:03
LeetCode
LeetCode题解
[置顶] LeetCode总结
除各个题目有特殊巧妙的解法以外,大部分题目都是经典的算法或者数据结构,因此做了如下小结,具体的解题思路可以搜索我的博客:
LeetCode题解
题目算法数据结构注意事项CloneGraphBFS哈希表WordLadderIIBFS
lanxu_yy
·
2014-01-04 20:00
LeetCode
算法
LeetCode题解
: Valid Number
ValidNumberValidateifagivenstringisnumeric.Someexamples:"0"=>true"0.1"=>true"abc"=>false"1a"=>false"2e10"=>trueNote:Itisintendedfortheproblemstatementtobeambiguous.Youshouldgatherallrequirementsupfron
MagiSu
·
2013-12-16 13:00
LeetCode
LeetCode题解
:Implement strStr()
ImplementstrStr()ImplementstrStr().Returnsapointertothefirstoccurrenceofneedleinhaystack,ornullifneedleisnotpartofhaystack.思路:首先想到的是KMP算法。不过似乎不是很成功,提交了之后总是报Runtimeerror,但是我这里无论本地机器跑还是在valgrind上跑都不报错。奇
MagiSu
·
2013-12-16 06:00
LeetCode
LeetCode题解
:LRU Cache
LRUCacheDesignandimplementadatastructureforLeastRecentlyUsed(LRU)cache.Itshouldsupportthefollowingoperations:getandset.get(key)-Getthevalue(willalwaysbepositive)ofthekeyifthekeyexistsinthecache,otherw
MagiSu
·
2013-12-02 16:00
LeetCode
LeetCode题解
:Wildcard Matching
WildcardMatchingImplementwildcardpatternmatchingwithsupportfor'?'and'*'.'?'Matchesanysinglecharacter. '*'Matchesanysequenceofcharacters(includingtheemptysequence). Thematchingshouldcovertheentireinpu
MagiSu
·
2013-11-30 03:00
LeetCode
LeetCode题解
:Sqrt(x)
Sqrt(x)Implementintsqrt(intx).Computeandreturnthesquarerootofx.思路:可以考虑二分搜索,但是二分搜索的起点不好判定,不过可以预先计算好numeric_limits::max()的平方根,然后搜索,这样范围就缩小很多而且避免了溢出。有的人用long来计算,这样在很多情况下也是可以避免溢出的。但是必须注意的是C++标准中long的最大值可以
MagiSu
·
2013-11-29 05:00
LeetCode
LeetCode题解
:Divide Two Integers
DivideTwoIntegersDividetwointegerswithoutusingmultiplication,divisionandmodoperator.思路:核心思想是:令试除数等于除数,如果试除数小于被除数,那么试除数乘二,商乘二,继续比较;否则试除数除二,商除二,被除数减去试除数,重新开始。这其实就是类似二分搜索法。题目有一些边边角角的特殊情况,比如int的最大值比最小值的绝对
MagiSu
·
2013-11-29 04:00
LeetCode
LeetCode题解
:Evaluate Reverse Polish Notation
EvaluateReversePolishNotationEvaluatethevalueofanarithmeticexpressioninReversePolishNotation.Validoperatorsare+,-,*,/.Eachoperandmaybeanintegeroranotherexpression.Someexamples:["2","1","+","3","*"]->(
MagiSu
·
2013-11-28 03:00
LeetCode
LeetCode题解
:Search in Rotated Sorted Array
SearchinRotatedSortedArraySupposeasortedarrayisrotatedatsomepivotunknowntoyoubeforehand.(i.e.,0124567mightbecome4567012).Youaregivenatargetvaluetosearch.Iffoundinthearrayreturnitsindex,otherwisereturn
MagiSu
·
2013-11-26 07:00
LeetCode
LeetCode题解
: Search for a Range
SearchforaRangeGivenasortedarrayofintegers,findthestartingandendingpositionofagiventargetvalue.Youralgorithm'sruntimecomplexitymustbeintheorderofO(logn).Ifthetargetisnotfoundinthearray,return[-1,-1].F
MagiSu
·
2013-11-26 06:00
LeetCode
LeetCode题解
:Surrounded Regions
SurroundedRegionsTotalAccepted:1947TotalSubmissions:13017Givena2Dboardcontaining'X'and'O',captureallregionssurroundedby'X'.Aregioniscapturedbyflippingall'O'sinto'X'sinthatsurroundedregion.Forexample,X
MagiSu
·
2013-11-26 04:00
LeetCode
LeetCode题解
: Reverse Linked List II
ReverseLinkedListIIReversealinkedlistfrompositionmton.Doitin-placeandinone-pass.Forexample:Given1->2->3->4->5->NULL,m=2andn=4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfythefollowingcondition:1≤m≤n≤
MagiSu
·
2013-11-26 03:00
LeetCode
LeetCode题解
: Construct Binary Tree from Preorder and Inorder Traversal
ConstructBinaryTreefromPreorderandInorderTraversalGivenpreorderandinordertraversalofatree,constructthebinarytree.Note:Youmayassumethatduplicatesdonotexistinthetree.思路:和inorder+postorder的思路类似。题解:/** *D
MagiSu
·
2013-11-25 15:00
LeetCode
LeetCode题解
: Construct Binary Tree from Inorder and Postorder Traversal
ConstructBinaryTreefromInorderandPostorderTraversalGiveninorderandpostordertraversalofatree,constructthebinarytree.Note:Youmayassumethatduplicatesdonotexistinthetree.思路:已知中序遍历和后序遍历的结果,要求反推树结构。首先注意到后序遍
MagiSu
·
2013-11-25 14:00
LeetCode
LeetCode题解
:Decode Ways
DecodeWaysAmessagecontaininglettersfromA-Zisbeingencodedtonumbersusingthefollowingmapping:'A'->1 'B'->2 ... 'Z'->26 Givenanencodedmessagecontainingdigits,determinethetotalnumberofwaystodecodeit.Forexa
MagiSu
·
2013-11-25 13:00
LeetCode
LeetCode题解
:Combinations
CombinationsGiventwointegersnandk,returnallpossiblecombinationsofknumbersoutof1...n.Forexample,Ifn=4andk=2,asolutionis:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 思路:递归填数即可。题解:classSolution{ public:
MagiSu
·
2013-11-25 03:00
LeetCode
LeetCode题解
:3sum closest
3SumClosestGivenanarraySofnintegers,findthreeintegersinSsuchthatthesumisclosesttoagivennumber,target.Returnthesumofthethreeintegers.Youmayassumethateachinputwouldhaveexactlyonesolution.Forexample,give
MagiSu
·
2013-11-25 00:00
LeetCode
LeetCode题解
:Combination Sum I and II
CombinationSumGivenasetofcandidatenumbers(C)andatargetnumber(T),findalluniquecombinationsinCwherethecandidatenumberssumstoT.ThesamerepeatednumbermaybechosenfromCunlimitednumberoftimes.Note:Allnumbers(
MagiSu
·
2013-11-25 00:00
LeetCode
LeetCode题解
:3Sum
3SumGivenanarraySofnintegers,arethereelementsa,b,cinSsuchthata+b+c=0?Findalluniquetripletsinthearraywhichgivesthesumofzero.Note:Elementsinatriplet(a,b,c)mustbeinnon-descendingorder.(ie,a≤b≤c)Thesoluti
MagiSu
·
2013-11-24 15:00
LeetCode
LeetCode题解
:Merge/Insert Interval
MergeIntervalsGivenacollectionofintervals,mergealloverlappingintervals.Forexample,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].InsertIntervalGivenasetofnon-overlappingintervals,insertane
MagiSu
·
2013-11-24 06:00
LeetCode
LeetCode题解
: Reverse Nodes in k-Group
ReverseNodesink-GroupGivenalinkedlist,reversethenodesofalinkedlistkatatimeandreturnitsmodifiedlist.Ifthenumberofnodesisnotamultipleofkthenleft-outnodesintheendshouldremainasitis.Youmaynotalterthevalue
MagiSu
·
2013-11-22 15:00
LeetCode
LeetCode题解
: Regular Expression Matching
RegularExpressionMatchingImplementregularexpressionmatchingwithsupportfor'.'and'*'.'.'Matchesanysinglecharacter. '*'Matcheszeroormoreoftheprecedingelement. Thematchingshouldcovertheentireinputstring(
MagiSu
·
2013-11-22 08:00
LeetCode
LeetCode题解
:String to Integer (atoi)
StringtoInteger(atoi)Implementatoitoconvertastringtoaninteger.Hint:Carefullyconsiderallpossibleinputcases.Ifyouwantachallenge,pleasedonotseebelowandaskyourselfwhatarethepossibleinputcases.Notes:Itisin
MagiSu
·
2013-11-19 05:00
LeetCode
LeetCode题解
:ZigZag Conversion
ZigZagConversionThestring"PAYPALISHIRING"iswritteninazigzagpatternonagivennumberofrowslikethis:(youmaywanttodisplaythispatterninafixedfontforbetterlegibility)PAHN APLSIIG YIR Andthenreadlinebyline:"PA
MagiSu
·
2013-11-19 05:00
LeetCode
LeetCode题解
:Longest Palindromic Substring
LongestPalindromicSubstringGivenastringS,findthelongestpalindromicsubstringinS.YoumayassumethatthemaximumlengthofSis1000,andthereexistsoneuniquelongestpalindromicsubstring.思路:只想到一个O(n^2)的解法。就是从左到右扫描起点
MagiSu
·
2013-11-19 04:00
LeetCode
LeetCode题解
:Sort List
SortListSortalinkedlistinO(nlogn)timeusingconstantspacecomplexity.思路:其实可以做一个快速排序或者merge排序之类的。但是这里的linkedlist是单向的,所以普通的快排办不到。不过仍然可以借用快速排序的思路,每次把链表分为三个部分:小于pivot,等于pivot和大于pivot,然后对小于大于pivot的部分进行排序。最后把三
MagiSu
·
2013-11-19 02:00
LeetCode
LeetCode题解
: Longest Consecutive Sequence
LongestConsecutiveSequenceGivenanunsortedarrayofintegers,findthelengthofthelongestconsecutiveelementssequence.Forexample,Given[100,4,200,1,3,2],Thelongestconsecutiveelementssequenceis[1,2,3,4].Returni
MagiSu
·
2013-11-17 09:00
LeetCode
LeetCode题解
: Flatten Binary Tree to Linked List
FlattenBinaryTreetoLinkedListGivenabinarytree,flattenittoalinkedlistin-place.Forexample,Given1 /\ 25 /\\ 346 Theflattenedtreeshouldlooklike:1 \ 2 \ 3 \ 4 \ 5 \ 6 思路:按preorder顺序访问树,使用迭代的方式进行。这样迭代过程中下一个
MagiSu
·
2013-11-17 07:00
LeetCode
LeetCode题解
: Binary Tree Zigzag Level Order Traversal
BinaryTreeZigzagLevelOrderTraversalGivenabinarytree,returnthezigzaglevelordertraversalofitsnodes'values.(ie,fromlefttoright,thenrighttoleftforthenextlevelandalternatebetween).Forexample:Givenbinarytre
MagiSu
·
2013-11-17 06:00
LeetCode
LeetCode题解
:Longest Valid Parentheses
LongestValidParenthesesGivenastringcontainingjustthecharacters'('and')',findthelengthofthelongestvalid(well-formed)parenthesessubstring.For"(()",thelongestvalidparenthesessubstringis"()",whichhaslengt
MagiSu
·
2013-11-17 00:00
LeetCode
LeetCode题解
:Set Matrix Zeroes
SetMatrixZeroesGivenamxnmatrix,ifanelementis0,setitsentirerowandcolumnto0.Doitinplace.思路:如果允许额外存储行和列清零的信息,那么题目就没有意思了。希望只用O(1)的存储空间的时候,我们就得利用矩阵本身的存储空间了:把清零的信息保存在第一行和第一列里。题解:classSolution{ public: voids
MagiSu
·
2013-11-16 12:00
LeetCode
LeetCode题解
:Word Break I and II
WordBreakGivenastringsandadictionaryofwordsdict,determineifscanbesegmentedintoaspace-separatedsequenceofoneormoredictionarywords.Forexample,givens="leetcode",dict=["leet","code"].Returntruebecause"lee
MagiSu
·
2013-11-15 05:00
LeetCode
LeetCode题解
:Rotate List
Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NU
·
2013-11-14 20:00
LeetCode
LeetCode题解
:Rotate List
RotateListGivenalist,rotatethelisttotherightbykplaces,wherekisnon-negative.Forexample:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.思路:这个题目的陷阱中,输入为空指针大约不算其中之一。主要的问题是k可以大于这个链表的总长度。这样,真正的旋转次数
MagiSu
·
2013-11-14 05:00
LeetCode
LeetCode题解
:Insertion Sort List
InsertionSortListSortalinkedlistusinginsertionsort.思路:标准的插入排序。就是考察一下链表的操作而已。题解:/** *Definitionforsingly-linkedlist. *structListNode{ *intval; *ListNode*next; *ListNode(intx):val(x),next(NULL){} *}; */
MagiSu
·
2013-11-14 01:00
LeetCode
LeetCode题解
:Add Two Numbers
AddTwoNumbersYouaregiventwolinkedlistsrepresentingtwonon-negativenumbers.Thedigitsarestoredinreverseorderandeachoftheirnodescontainasingledigit.Addthetwonumbersandreturnitasalinkedlist.Input:(2->4->3)
MagiSu
·
2013-11-13 13:00
LeetCode
LeetCode题解
:Add Binary
AddBinaryGiventwobinarystrings,returntheirsum(alsoabinarystring).Forexample,a="11"b="1"Return"100".思路:小学编程竞赛题。题解:classSolution{ public: stringaddBinary(stringa,stringb){ boolcarry=false; constintLenA
MagiSu
·
2013-11-13 13:00
LeetCode
LeetCode题解
:Longest Substring Without Repeating Characters
LongestSubstringWithoutRepeatingCharactersGivenastring,findthelengthofthelongestsubstringwithoutrepeatingcharacters.Forexample,thelongestsubstringwithoutrepeatinglettersfor"abcabcbb"is"abc",whichthele
MagiSu
·
2013-11-13 13:00
LeetCode
LeetCode题解
:Longest Common Prefix
LongestCommonPrefixWriteafunctiontofindthelongestcommonprefixstringamongstanarrayofstrings.思路:两个字符串的LCP可以通过依次比较相应字符的方法来完成。题解:classSolution{ public: stringlcp(conststring&s1,conststring&s2) { constintL
MagiSu
·
2013-11-13 12:00
LeetCode
LeetCode题解
: Validate Binary Search Tree
ValidateBinarySearchTreeGivenabinarytree,determineifitisavalidbinarysearchtree(BST).AssumeaBSTisdefinedasfollows:Theleftsubtreeofanodecontainsonlynodeswithkeyslessthanthenode'skey.Therightsubtreeofano
MagiSu
·
2013-11-13 12:00
LeetCode
上一页
25
26
27
28
29
30
31
32
下一页
按字母分类:
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
其他