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题解
(1)--Two Sum
原题: https://leetcode.com/problems/two-sum/ Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should
·
2015-11-02 17:33
LeetCode
[LeetCode] 4Sum
算法渣,现实基本都参考或者完全拷贝[戴方勤(
[email protected]
)]大神的
leetcode题解
,此处仅作刷题记录。
·
2015-11-02 17:23
LeetCode
[LeetCode] 3Sum Closest
算法渣,现实基本都参考或者完全拷贝[戴方勤(
[email protected]
)]大神的
leetcode题解
,此处仅作刷题记录。
·
2015-11-02 17:21
LeetCode
[LeetCode] 3Sum
算法渣,现实基本都参考或者完全拷贝[戴方勤(
[email protected]
)]大神的
leetcode题解
,此处仅作刷题记录。
·
2015-11-02 17:21
LeetCode
[LeetCode] Two Sum
算法渣,现实基本都参考或者完全拷贝[戴方勤(
[email protected]
)]大神的
leetcode题解
,此处仅作刷题记录。
·
2015-11-02 17:20
LeetCode
[
LeetCode题解
]: Sort Colors
前言 【LeetCode 题解】系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given an array with n objects colored red, white or blue, sort them so that objects of th
·
2015-11-01 11:57
LeetCode
LeetCode题解
(20)--Valid Parentheses
https://leetcode.com/problems/valid-parentheses/ 原题: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string i
·
2015-10-31 16:01
LeetCode
LeetCode题解
(19)--Remove Nth Node From End of List
https://leetcode.com/problems/remove-nth-node-from-end-of-list/ 原题: Given a linked list, remove the nth node from the end of
·
2015-10-31 16:00
LeetCode
LeetCode题解
(14)--Longest Common Prefix
https://leetcode.com/problems/longest-common-prefix/ 原题: Write a function to find the longest common prefix string amongst an array of strings. 思路: 简单,直接遍历查找即可。 AC代码: 1 class Solution { 2 pu
·
2015-10-31 16:59
LeetCode
LeetCode题解
(12)--Integer to Roman
https://leetcode.com/problems/integer-to-roman/ 原题: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 思路: 掌握罗马数字规则并实现即可。(具体规则见&nb
·
2015-10-31 16:58
LeetCode
LeetCode题解
——Kth Largest Element in an Array
Findthe kthlargestelementinanunsortedarray.Notethatitisthekthlargestelementinthesortedorder,notthekthdistinctelement.Forexample,Given [3,2,1,5,6,4] andk=2,return5.Note: Youmayassumekisalwaysvalid,1≤k≤
u010025211
·
2015-10-27 15:00
LeetCode
array
partition
kth
Largest
LeetCode题解
——Number of Digit One
Givenanintegern,countthetotalnumberofdigit1appearinginallnon-negativeintegerslessthanorequalton.Forexample:Givenn=13,Return6,becausedigit1occurredinthefollowingnumbers:1,10,11,12,13.解题思路:想法一:从一到n依次计算每
u010025211
·
2015-10-27 14:00
LeetCode
Math
number
one
of
digit
LeetCode题解
——Factorial Trailing Zeroes
Givenaninteger n,returnthenumberoftrailingzeroesin n!.Note: Yoursolutionshouldbeinlogarithmictimecomplexity.出现0的情况是,出现5和2的倍数。[n/k]代表1~n中能被k整除的个数,而能被2整除的个数多余能被5整除的个数,故只要知道能被5整除的个数即可。那么怎样计算n!的质因子中所有5的个数
u010025211
·
2015-10-27 11:00
LeetCode
factorial
trailing
zeroes
LeetCode题解
——Count Primes
escription:Countthenumberofprimenumberslessthananon-negativenumber, n.Hint:Let'sstartwitha isPrime function.Todetermineifanumberisprime,weneedtocheckifitisnotdivisiblebyanynumberlessthan n.Theruntimec
u010025211
·
2015-10-26 21:00
LeetCode
count
Prime
LeetCode题解
——Ugly Number II
Writeaprogramtofindthe n-thuglynumber.Uglynumbersarepositivenumberswhoseprimefactorsonlyinclude 2,3,5.Forexample, 1,2,3,4,5,6,8,9,10,12 isthesequenceofthefirst 10 uglynumbers.Notethat 1 istypicallytre
u010025211
·
2015-10-22 19:00
LeetCode
number
丑数
Ugly
LeetCode题解
——Happy Number
Writeanalgorithmtodetermineifanumberis"happy".Ahappynumberisanumberdefinedbythefollowingprocess:Startingwithanypositiveinteger,replacethenumberbythesumofthesquaresofitsdigits,andrepeattheprocessuntilt
u010025211
·
2015-10-22 19:00
set
hash
number
happy
LeetCode题解
——Multiply Strings
Giventwonumbersrepresentedasstrings,returnmultiplicationofthenumbersasastring.Note:Thenumberscanbearbitrarilylargeandarenon-negative.此题可以用来求两个大数相乘。思路:逐位相乘处理进位法。假设两个字符串a和b以及保存结果的字符串c.对每个i,j;将a[i]*b[j]的
u010025211
·
2015-10-16 16:00
String
strings
大数相乘
mutiply
LeetCode题解
——Plus One
Givenanon-negativenumberrepresentedasanarrayofdigits,plusonetothenumber.Thedigitsarestoredsuchthatthemostsignificantdigitisattheheadofthelist.思路:从尾到头逐位遍历字符串,如果当前字符不为‘9’,那么直接将此字符加1,返回。如果当前字符为‘9’,那么将此字符
u010025211
·
2015-10-16 14:00
String
bit
compute
LeetCode题解
——Add Binary
Giventwobinarystrings,returntheirsum(alsoabinarystring).Forexample,a= "11"b= "1"Return "100".思路:最直接的想法,从最后一位开始,逐位运算。classSolution{ public: //特殊输入:空字符串,10+1;11+11,1111+11,1011+11; stringaddBinary(strin
u010025211
·
2015-10-16 14:00
String
binary
LeetCode题解
:Sum Root to Leaf Numbers
Givenabinarytreecontainingdigitsfrom0-9only,eachroot-to-leafpathcouldrepresentanumber.Anexampleistheroot-to-leafpath1->2->3whichrepresentsthenumber123.Findthetotalsumofallroot-to-leafnumbers.Forexampl
u012403246
·
2015-10-02 21:00
LeetCode
LeetCode题解
:Word Ladder
Giventwowords(beginWordandendWord),andadictionary’swordlist,findthelengthofshortesttransformationsequencefrombeginWordtoendWord,suchthat:OnlyonelettercanbechangedatatimeEachintermediatewordmustexistin
u012403246
·
2015-10-02 21:00
LeetCode
LeetCode题解
:Best Time to Buy and Sell Stock II
Sayyouhaveanarrayforwhichtheithelementisthepriceofagivenstockondayi.Designanalgorithmtofindthemaximumprofit.Youmaycompleteasmanytransactionsasyoulike(ie,buyoneandselloneshareofthestockmultipletimes).H
u012403246
·
2015-10-02 21:00
LeetCode
LeetCode题解
:Best Time to Buy and Sell Stock
Sayyouhaveanarrayforwhichtheithelementisthepriceofagivenstockondayi.Ifyouwereonlypermittedtocompleteatmostonetransaction(ie,buyoneandselloneshareofthestock),designanalgorithmtofindthemaximumprofit.题意:
u012403246
·
2015-10-02 21:00
LeetCode
LeetCode题解
:Triangle
Givenatriangle,findtheminimumpathsumfromtoptobottom.Eachstepyoumaymovetoadjacentnumbersontherowbelow.Forexample,giventhefollowingtriangle[[2],[3,4],[6,5,7],[4,1,8,3]]Theminimumpathsumfromtoptobottomis
u012403246
·
2015-10-02 21:00
LeetCode
LeetCode题解
:Populating Next Right Pointers in Each Node
GivenabinarytreestructTreeLinkNode{ TreeLinkNode*left; TreeLinkNode*right; TreeLinkNode*next; } Populateeachnextpointertopointtoitsnextrightnode.Ifthereisnonextrightnode,thenextpointershouldbesettoNUL
u012403246
·
2015-10-02 21:00
LeetCode
LeetCode题解
:Flatten Binary Tree to Linked List
Givenabinarytree,flattenittoalinkedlistin-place.Forexample,Given1 /\ 25 /\\ 346 Theflattenedtreeshouldlooklike:1\2\3\4\5\6题意:看不懂……弄了几棵树跑结果发现是先序遍历解决思路:先序遍历代码:publicclassSolution{ publicvoidflatten(Tree
u012403246
·
2015-10-02 20:00
LeetCode
LeetCode题解
:Path Sum II
Givenabinarytreeandasum,findallroot-to-leafpathswhereeachpath’ssumequalsthegivensum.Forexample:Giventhebelowbinarytreeandsum=22,5/\48//\11134/\/\7251return[[5,4,11,2],[5,8,4,5]]题意:给定一棵二叉树,找到所有根->叶子结点的
u012403246
·
2015-10-02 20:00
LeetCode
LeetCode题解
:Convert Sorted List to Binary Search Tree
Givenasinglylinkedlistwhereelementsaresortedinascendingorder,convertittoaheightbalancedBST.题意:给定一个升序排列的单链表,转换为二叉搜索树解决思路:同样是二分……代码:publicclassSolution{ privateListNodenode; publicTreeNodesortedListToB
u012403246
·
2015-10-02 20:00
LeetCode
LeetCode题解
:Convert Sorted Array to Binary Search Tree
Givenanarraywhereelementsaresortedinascendingorder,convertittoaheightbalancedBST.题意:给定一个升序数组,将它转换为二叉搜索树解决思路:二分……代码:publicclassSolution{ publicTreeNodesortedArrayToBST(int[]num){ if(num.length==0){ ret
u012403246
·
2015-10-02 20:00
LeetCode
LeetCode题解
:Construct Binary Tree from Inorder and Postorder Traversal
Giveninorderandpostordertraversalofatree,constructthebinarytree.Note:Youmayassumethatduplicatesdonotexistinthetree.题解:通过中序遍历和后序遍历还原二叉树解决思路:首先要明确一点,对于后序遍历的结果,如果一个元素所在的位置为i,若在中序遍历的i-1位置的元素为该元素的根结点,说明该元素
u012403246
·
2015-10-02 20:00
LeetCode
LeetCode题解
:Construct Binary Tree from Preorder and Inorder Traversal
Givenpreorderandinordertraversalofatree,constructthebinarytree.Note:Youmayassumethatduplicatesdonotexistinthetree.题意:给定一棵树的前序遍历和中序遍历,还原二叉树解决思路:我们可以知道的是,前序遍历的第一个结点就是根节点,而且对于中序遍历,每一个根节点的左边是其左子树,右边是其右子树。
u012403246
·
2015-10-02 20:00
LeetCode
LeetCode题解
:Binary Tree Zigzag Level Order Traversal
Givenabinarytree,returnthezigzaglevelordertraversalofitsnodes’values.(ie,fromlefttoright,thenrighttoleftforthenextlevelandalternatebetween).Forexample:Givenbinarytree{3,9,20,#,#,15,7},3/\920/\157retur
u012403246
·
2015-10-02 20:00
LeetCode
LeetCode题解
:Validate Binary Search Tree
Givenabinarytree,determineifitisavalidbinarysearchtree(BST).AssumeaBSTisdefinedasfollows:Theleftsubtreeofanodecontainsonlynodeswithkeyslessthanthenode’skey.Therightsubtreeofanodecontainsonlynodeswithk
u012403246
·
2015-10-02 20:00
LeetCode
LeetCode题解
:Unique Binary Search Trees II
Givenn,generateallstructurallyuniqueBST’s(binarysearchtrees)thatstorevalues1…n.Forexample,Givenn=3,yourprogramshouldreturnall5uniqueBST’sshownbelow.13321\///\\321132//\\2123题意:给定n,求出结点取值在1->n的二叉搜索树所有表
u012403246
·
2015-10-02 20:00
LeetCode
LeetCode题解
:Unique Binary Search Trees
Givenn,howmanystructurallyuniqueBST’s(binarysearchtrees)thatstorevalues1…n?Forexample,Givenn=3,thereareatotalof5uniqueBST’s.13321\///\\321132//\\2123题意:给定一个整数n代表二叉搜索树所能存储的最大整数,树中元素大小为1->n。在此情况下,求出二叉搜索
u012403246
·
2015-10-02 19:00
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
上一页
23
24
25
26
27
28
29
30
下一页
按字母分类:
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
其他