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题解
:Binary Tree Inorder Traversal
Givenabinarytree,returntheinordertraversalofitsnodes’values.Forexample:Givenbinarytree{1,#,2,3},1\2/3return[1,3,2].题意:中序遍历二叉树解决思路:”左根右“的递归或者通过栈完成的迭代代码:publicclassSolution{ publicListinorderTraversal(T
u012403246
·
2015-10-02 19:00
LeetCode
LeetCode题解
:Restore IP Addresses
Givenastringcontainingonlydigits,restoreitbyreturningallpossiblevalidIPaddresscombinations.Forexample:Given“25525511135”,return[“255.255.11.135”,“255.255.111.35”].(Orderdoesnotmatter)题意:给定一个字符串,判断其代表的
u012403246
·
2015-10-02 19:00
LeetCode
LeetCode题解
:Reverse Linked List II
Reversealinkedlistfrompositionmton.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≤lengthoflist.题意:给定整
u012403246
·
2015-10-02 19:00
LeetCode
LeetCode题解
:Decode Ways
AmessagecontaininglettersfromA-Zisbeingencodedtonumbersusingthefollowingmapping:‘A’->1‘B’->2…‘Z’->26Givenanencodedmessagecontainingdigits,determinethetotalnumberofwaystodecodeit.Forexample,Givenencode
u012403246
·
2015-10-02 19:00
LeetCode
LeetCode题解
——Convert Sorted Array to Binary Search Tree
Givenanarraywhereelementsaresortedinascendingorder,convertittoaheightbalancedBST./** *Definitionforabinarytreenode. *structTreeNode{ *intval; *TreeNode*left; *TreeNode*right; *TreeNode(intx):val(x),le
u010025211
·
2015-09-30 16:00
LeetCode
array
tree
binary
LeetCode题解
——Convert Sorted List to Binary Search Tree
Givenasinglylinkedlistwhereelementsaresortedinascendingorder,convertittoaheightbalancedBST.分析:要求最后得到一颗平衡二叉树,那么链表的中间节点就是二叉树的根节点,中间节点左边就是二叉树的左子树,中间节点右边就是二叉树的右子树首先找到链表的中间节点作为BST的根节点,根节点的左子树是以中间节点左边的节点建立的
u010025211
·
2015-09-30 16:00
LeetCode
list
tree
binary
LeetCode题解
——Implement Queue using Stacks
Implementthefollowingoperationsofaqueueusingstacks.push(x)--Pushelementxtothebackofqueue.pop()--Removestheelementfrominfrontofqueue.peek()--Getthefrontelement.empty()--Returnwhetherthequeueisempty.Not
u010025211
·
2015-09-29 15:00
LeetCode
Queue
stack
LeetCode题解
——Implement Stack using Queues
Implementthefollowingoperationsofastackusingqueues.push(x)--Pushelementxontostack.pop()--Removestheelementontopofthestack.top()--Getthetopelement.empty()--Returnwhetherthestackisempty.Notes:Youmustuse
u010025211
·
2015-09-29 15:00
LeetCode
Queue
stcak
LeetCode题解
——Add Digits
Givenanon-negativeinteger num,repeatedlyaddallitsdigitsuntiltheresulthasonlyonedigit.Forexample:Given num=38,theprocessislike: 3+8=11, 1+1=2.Since 2 hasonlyonedigit,returnit.Followup:Couldyoudoitwitho
u010025211
·
2015-09-29 11:00
LeetCode
Math
LeetCode题解
——Linked List Cycle II
explannationfrom:http://stackoverflow.com/questions/2936213/explain-how-finding-cycle-start-node-in-cycle-linked-list-workLetmetrytoclarifythecycledetectionalgorithmthatisprovidedathttp://en.wikipedia
u010025211
·
2015-09-25 11:00
LeetCode
list
linked
LeetCode题解
——Linked List Cycle
Givenalinkedlist,determineifithasacycleinit.Followup:Canyousolveitwithoutusingextraspace?/** *Definitionforsingly-linkedlist. *structListNode{ *intval; *ListNode*next; *ListNode(intx):val(x),next(NULL
u010025211
·
2015-09-25 10:00
LeetCode
list
linked
LeetCode题解
——Intersection of Two Linked Lists
Writeaprogramtofindthenodeatwhichtheintersectionoftwosinglylinkedlistsbegins.Forexample,thefollowingtwolinkedlists:A:a1→a2 ↘ c1→c2→c3 ↗ B:b1→b2→b3 begintointersectatnodec1.Notes:Ifthetwolinkedlistshav
u010025211
·
2015-09-25 09:00
LeetCode
LinkedList
LeetCode题解
——Rotate Array
Rotateanarrayof n elementstotherightby k steps.Forexample,with n =7and k =3,thearray [1,2,3,4,5,6,7] isrotatedto [5,6,7,1,2,3,4].Note:Trytocomeupasmanysolutionsasyoucan,thereareatleast3differentwaysto
u010025211
·
2015-09-23 14:00
LeetCode
array
LeetCode题解
:Subsets II
Givenacollectionofintegersthatmightcontainduplicates,nums,returnallpossiblesubsets.Note:Elementsinasubsetmustbeinnon-descendingorder.Thesolutionsetmustnotcontainduplicatesubsets.Forexample,Ifnums=[1,2
u012403246
·
2015-09-06 21:00
LeetCode题解
:Subsets
Givenasetofdistinctintegers,nums,returnallpossiblesubsets.Note:Elementsinasubsetmustbeinnon-descendingorder.Thesolutionsetmustnotcontainduplicatesubsets.Forexample,Ifnums=[1,2,3],asolutionis:[[3],[1],
u012403246
·
2015-09-06 21:00
LeetCode题解
:Search Insert Position
Givenasortedarrayandatargetvalue,returntheindexifthetargetisfound.Ifnot,returntheindexwhereitwouldbeifitwereinsertedinorder.Youmayassumenoduplicatesinthearray.Herearefewexamples.[1,3,5,6],5→2[1,3,5,6]
u012403246
·
2015-09-06 21:00
LeetCode题解
:Group Anagrams
Givenanarrayofstrings,groupanagramstogether.Forexample,given:[“eat”,“tea”,“tan”,“ate”,“nat”,“bat”],Return:[[“ate”,“eat”,”tea”],[“nat”,”tan”],[“bat”]]Note:Forthereturnvalue,eachinnerlist’selementsmustf
u012403246
·
2015-09-06 21:00
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].题意:求出给定数字的所有组合可能解决思路:先加入第一个元素,然后把第二个元素插入两个位置中,
u012403246
·
2015-09-06 21:00
LeetCode题解
:Search for a Range
Givenasortedarrayofintegers,findthestartingandendingpositionofagiventargetvalue.Youralgorithm’sruntimecomplexitymustbeintheorderofO(logn).Ifthetargetisnotfoundinthearray,return[-1,-1].Forexample,Given
u012403246
·
2015-09-06 21:00
LeetCode题解
:Next Permutation
Implementnextpermutation,whichrearrangesnumbersintothelexicographicallynextgreaterpermutationofnumbers.Ifsucharrangementisnotpossible,itmustrearrangeitasthelowestpossibleorder(ie,sortedinascendingorde
u012403246
·
2015-09-06 21:00
LeetCode题解
:Divide Two Integers
Dividetwointegerswithoutusingmultiplication,divisionandmodoperator.Ifitisoverflow,returnMAX_INT.题意:不使用乘,除,模符号作除法运算解决思路:每一个数都可以用2进制表示,利用这一点通过位运算完成代码:publicclassSolution{ publicintdivide(intdividend,int
u012403246
·
2015-09-06 20:00
LeetCode题解
:Swap Nodes in Pairs
Givenalinkedlist,swapeverytwoadjacentnodesandreturnitshead.Forexample,Given1->2->3->4,youshouldreturnthelistas2->1->4->3.Youralgorithmshoulduseonlyconstantspace.Youmaynotmodifythevaluesinthelist,onlyn
u012403246
·
2015-09-06 20:00
LeetCode题解
:Construct Binary Tree from Preorder and Inorder Traversal
Givenpreorderandinordertraversalofatree,constructthebinarytree.Note:Youmayassumethatduplicatesdonotexistinthetree.题意:给定一棵树的先序遍历和中序遍历,还原该树解决思路:在中序遍历中,每一个根节点的左方为其左子树,右方为右子树;而在先序遍历中第一个节点为根节点。利用这两点可以解决代码:
u012403246
·
2015-09-06 20:00
leetcode题解
/** *Definitionforsingly-linkedlist. *structListNode{ *intval; *ListNode*next; *ListNode(intx):val(x),next(NULL){} *}; */ classSolution{ public: boolisPalindrome(ListNode*head){ if(head==NULL||head->n
xtzmm1215
·
2015-08-27 21:00
LeetCode题解
:Add Digits
Givenanon-negativeintegernum,repeatedlyaddallitsdigitsuntiltheresulthasonlyonedigit.Forexample:Givennum=38,theprocessislike:3+8=11,1+1=2.Since2hasonlyonedigit,returnit.题意:给定非负整数,不断把各位数字相加,直到结果是个位数。例如3
u012403246
·
2015-08-21 09:00
LeetCode题解
:Binary Tree Paths
Givenabinarytree,returnallroot-to-leafpaths.Forexample,giventhefollowingbinarytree:1/\23\5Allroot-to-leafpathsare:["1->2->5","1->3"]题意:给定一颗二叉树,返回所有从根节点到叶节点的路径解决思路:DFS代码:publicclassSolution{ publicList
u012403246
·
2015-08-21 09:00
LeetCode题解
:Roman to Integer
Givenaromannumeral,convertittoaninteger.Inputisguaranteedtobewithintherangefrom1to3999.题意:给定一个1-3999范围内的罗马数字,把它转换为整数解决思路:按照罗马数字转换代码:publicclassSolution{ publicintromanToInt(Strings){ intres=0; for(int
u012403246
·
2015-08-21 09:00
LeetCode题解
:Longest Common Prefix
Writeafunctiontofindthelongestcommonprefixstringamongstanarrayofstrings.题意:找出字符串数组中最长的共有前缀解决思路:遍历所有字符串从头到尾找共有前缀代码:publicclassSolution{ publicStringlongestCommonPrefix(String[]strs){ if(strs.length==0)
u012403246
·
2015-08-21 09:00
LeetCode题解
:Remove Nth Node From End of List
Givenalinkedlist,removethenthnodefromtheendoflistandreturnitshead.Forexample,Givenlinkedlist:1->2->3->4->5,andn=2.Afterremovingthesecondnodefromtheend,thelinkedlistbecomes1->2->3->5.Note:Givennwillalw
u012403246
·
2015-08-21 09:00
LeetCode题解
:Contains Duplicate II
Givenanarrayofintegersandanintegerk,findoutwhethertherearetwodistinctindicesiandjinthearraysuchthatnums[i]=nums[j]andthedifferencebetweeniandjisatmostk.题意:给定数组和整数k,找出数组内相同元素,且两个元素距离小于等于k解决思路:和前一个思路一样,
u012403246
·
2015-08-12 11:00
LeetCode
LeetCode题解
:Contains Duplicate
Givenanarrayofintegers,findifthearraycontainsanyduplicates.Yourfunctionshouldreturntrueifanyvalueappearsatleasttwiceinthearray,anditshouldreturnfalseifeveryelementisdistinct.题意:给定一个整数数组,判断是否含有重复元素解决思路
u012403246
·
2015-08-12 11:00
LeetCode
LeetCode题解
:Rectangle Area
Findthetotalareacoveredbytworectilinearrectanglesina2Dplane.Eachrectangleisdefinedbyitsbottomleftcornerandtoprightcornerasshowninthefigure.Assumethatthetotalareaisneverbeyondthemaximumpossiblevalueofi
u012403246
·
2015-08-12 11:00
LeetCode
LeetCode题解
:Implement Stack using Queues
Implementthefollowingoperationsofastackusingqueues.push(x)–Pushelementxontostack.pop()–Removestheelementontopofthestack.top()–Getthetopelement.empty()–Returnwhetherthestackisempty.Notes:Youmustuseonly
u012403246
·
2015-08-12 11:00
LeetCode
LeetCode题解
:Invert Binary Tree
Invertabinarytree.4/\27/\/\1369to4/\72/\/\9631题意:将二叉树的左右子树互换解决思路:DFS或BFS代码:DFS:publicTreeNodeinvertTree(TreeNoderoot){ if(root==null){ returnnull; } finalTreeNodeleft=root.left, right=root.right; roo
u012403246
·
2015-08-12 10:00
LeetCode
LeetCode题解
:Summary Ranges
Givenasortedintegerarraywithoutduplicates,returnthesummaryofitsranges.Forexample,given[0,1,2,4,5,7],return[“0->2”,”4->5”,”7”].题意:给定一个有序数组,数组内没有重复元素,返回一个代表数组内数据范围的数组。解决思路:从左往右遍历,当后一个元素与当前元素差不为1的时候就输出数据
u012403246
·
2015-08-12 10:00
LeetCode
LeetCode题解
:Power of Two
Givenaninteger,writeafunctiontodetermineifitisapoweroftwo.题意:给定一个整数,判断是否为2的幂解决思路:如果一个整数n是2的幂,那么让n和n-1进行与运算必然为0(位运算)代码:publicbooleanisPowerOfTwo(intn){ return((n&(n-1))==0&&n>0); }
u012403246
·
2015-08-12 10:00
LeetCode
LeetCode题解
:Implement Queue using Stacks
Implementthefollowingoperationsofaqueueusingstacks.push(x)–Pushelementxtothebackofqueue.pop()–Removestheelementfrominfrontofqueue.peek()–Getthefrontelement.empty()–Returnwhetherthequeueisempty.Notes:Y
u012403246
·
2015-08-12 10:00
LeetCode
LeetCode题解
:Palindrome Linked List
Givenasinglylinkedlist,determineifitisapalindrome.Followup:CouldyoudoitinO(n)timeandO(1)space?题意:给定一个单向链表,判断是否为回文解决思路:假设一个链表是回文,那么把链表分割为1…n/2,n/2+1…n两个部分,这两个部分肯定是相同的(把第二部分顺序逆转过来或者逆转第一部分)。所以如果我们能把任何一个部
u012403246
·
2015-08-12 10:00
LeetCode
LeetCode题解
:Lowest Common Ancestor of a Binary Search Tree
Givenabinarysearchtree(BST),findthelowestcommonancestor(LCA)oftwogivennodesintheBST.AccordingtothedefinitionofLCAonWikipedia:“ThelowestcommonancestorisdefinedbetweentwonodesvandwasthelowestnodeinTthat
u012403246
·
2015-08-12 10:00
LeetCode
LeetCode题解
:Delete Node in a Linked List
Writeafunctiontodeleteanode(exceptthetail)inasinglylinkedlist,givenonlyaccesstothatnode.Supposedthelinkedlistis1->2->3->4andyouaregiventhethirdnodewithvalue3,thelinkedlistshouldbecome1->2->4aftercalli
u012403246
·
2015-08-12 10:00
LeetCode
LeetCode题解
:Pascal's Triangle II
Givenanindexk,returnthekthrowofthePascal’striangle.Forexample,givenk=3,Return[1,3,3,1].Note:CouldyouoptimizeyouralgorithmtouseonlyO(k)extraspace?题意:返回给定k对应第k行的Pascal三角形解决思路:其实很简单,把Pascal三角形的解决办法改一改就可以
u012403246
·
2015-08-12 10:00
LeetCode
LeetCode题解
:Pascal's Triangle
GivennumRows,generatethefirstnumRowsofPascal’striangle.Forexample,givennumRows=5,Return[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]题意是:给定一个正整数numRows代表行数,返回对应行数的Pascal三角形。解决这个问题的办法很简单了,根据Pascal三角形的特征计算就可
u012403246
·
2015-08-12 10:00
LeetCode
[leetcode] 040. Combination Sum II (Medium) (C++)
索引:[LeetCode]
Leetcode题解
索引(C++/Java/Python/Sql)Github:https://github.com/illuz/leetcode040.CombinationSumII
hcbbt
·
2015-08-08 08:00
LeetCode
C++
算法
[LeetCode] 039. Combination Sum (Medium) (C++)
索引:[LeetCode]
Leetcode题解
索引(C++/Java/Python/Sql)Github:https://github.com/illuz/leetcode039.CombinationSum
hcbbt
·
2015-08-08 08:00
LeetCode
C++
算法
[LeetCode] 038. Count and Say (Easy) (C++/Python)
索引:[LeetCode]
Leetcode题解
索引(C++/Java/Python/Sql)Github:https://github.com/illuz/leetcode038.CountandSay
hcbbt
·
2015-07-30 10:00
LeetCode
C++
算法
python
收藏 - 随时更新
Markdown参考 说明文档 在线转换 编辑器 博客 chensidney's blog 算法、数据结构、 ACM 一线码农 经典算法 HZWER OJ大神
LeetCode
·
2015-07-18 13:00
更新
LeetCode题解
——Longest Palindromic Substring
转自:http://blog.csdn.net/hopeztm/article/details/7932245题目: GivenastringS,findthelongestpalindromicsubstringinS.给出一个字符串S,找到一个最长的连续回文串。例如串 babcbabcbaccba最长回文是:abcbabcba这个题目小弟给出3中解法,前两种的都是O(n^2),第三种思路是O(
u010025211
·
2015-07-03 21:00
LeetCode
String
回文字符串
LeetCode题解
——4Median of Two Sorted Arrays
MedianofTwoSortedArraysTherearetwosortedarrays nums1 and nums2 ofsizemandnrespectively.Findthemedianofthetwosortedarrays.TheoverallruntimecomplexityshouldbeO(log(m+n)).1.mergeO(n+m)2.kthsmallestofsort
u010025211
·
2015-07-03 19:00
LeetCode
array
search
binary
kth
Smallest
LeetCode题解
4:Median of Two Sorted Arrays
MedianofTwoSortedArrays问题:求2个有序数组的中位数,要求算法时间复杂度为O(log(m+n))。难度:困难思路:此题为“在2个有序数组中寻找第k个元素”问题的变体。根据中位数的定义,此题可转化为“在2个有序数组中寻找第‘(m+n)/2’个元素”。算法难点在于要求时间复杂度为O(log(m+n)),因此需要充分利用2个数组有序这一条件,每次循环将搜索空间缩小一半。陷阱:数组下
沙札罕
·
2015-07-02 23:08
LeetCode题解
2:Add two numbers
Addtwonumbers问题:给定2个用链表(LinkedList)表示的10进制非负整数,求它们的和。难度:容易思路:遍历2个链表,按位求和。陷阱:进位处理;两个链表长度不同代码:#Definitionforsingly-linkedlist.#classListNode(object):#def__init__(self,x):#self.val=x#self.next=NoneclassS
沙札罕
·
2015-06-30 18:26
上一页
24
25
26
27
28
29
30
31
下一页
按字母分类:
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
其他