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题解
——Basic Calculator
Theexpressionstringmaycontainopen ( andclosingparentheses ),theplus + orminussign -, non-negative integersandemptyspaces .Youmayassumethatthegivenexpressionisalwaysvalid.Someexamples:"1+1"=2 "2-1+2"=3
u010025211
·
2015-11-08 17:00
LeetCode
String
stack
Parentheses
LeetCode题解
——Different Ways to Add Parentheses
Givenastringofnumbersandoperators,returnallpossibleresultsfromcomputingallthedifferentpossiblewaystogroupnumbersandoperators.Thevalidoperatorsare+, - and *.Example1Input: "2-1-1".((2-1)-1)=0 (2-(1-1))
u010025211
·
2015-11-08 11:00
LeetCode
String
dp
recursively
LeetCode题解
——Unique Binary Search Trees II
Given n,generateallstructurallyunique BST's (binarysearchtrees)thatstorevalues1...n.Forexample,Given n =3,yourprogramshouldreturnall5uniqueBST'sshownbelow.13321 \///\\ 321132 //\\ 2123 想法一:递归,思想见Uniqu
u010025211
·
2015-11-07 22:00
LeetCode
unique
BST
BST
LeetCode题解
——Unique Binary Search Trees
题目:Given n,howmanystructurallyunique BST's (binarysearchtrees)thatstorevalues1...n?Forexample,Given n =3,thereareatotalof5uniqueBST's.13321 \///\\ 321132 //\\ 2123解题思路:Theproblemcanbesolvedinadynamicp
u010025211
·
2015-11-07 20:00
LeetCode
unique
BST
BST
LeetCode题解
——Symmetric Tree
题目:Givenabinarytree,checkwhetheritisamirrorofitself(ie,symmetricarounditscenter).Forexample,thisbinarytreeissymmetric:1 /\ 22 /\/\ 3443 Butthefollowingisnot:1 /\ 22 \\ 33 解题思路:(1)如果一个树是对称的,那么左子树和右子树的关
u010025211
·
2015-11-06 14:00
LeetCode
tree
Symmetric
LeetCode题解
——Copy List with Random Pointer
Alinkedlistisgivensuchthateachnodecontainsanadditionalrandompointerwhichcouldpointtoanynodeinthelistornull.Returnadeepcopyofthelist.Subscribe toseewhichcompaniesaskedthisquestionAsanoptimisedsolution,
u010025211
·
2015-11-03 21:00
LeetCode
list
copy
Random
pointer
linked
LeetCode题解
——Binary Search Tree Iterator
mplementaniteratoroverabinarysearchtree(BST).YouriteratorwillbeinitializedwiththerootnodeofaBST.Calling next() willreturnthenextsmallestnumberintheBST.Note: next() and hasNext() shouldruninaverageO(1)
u010025211
·
2015-11-03 18:00
LeetCode
tree
search
iterator
binary
LeetCode题解
——Reverse Words in a String
Givenaninputstring,reversethestringwordbyword.Forexample,Givens="theskyisblue",return"blueisskythe".Trytosolveit in-place in O(1)space.Clarification:Whatconstitutesaword?Asequenceofnon-spacecharacters
u010025211
·
2015-11-03 17:00
LeetCode
String
reverse
words
LeetCode题解
(13)--Roman to Integer
https://leetcode.com/problems/roman-to-integer/ 原题: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 思路: 关键是要搞清罗马数字规则。PS:不用考虑错误输
·
2015-11-02 17:39
LeetCode
LeetCode题解
(9)--Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. 思想: 先计算出这个整数的逆序数,然后比较它和原来的数每位是否都相同即可。另外要注意负数没有回文数,还应该考虑overflow一定不是回文数。 AC代码: 1 class Solution { 2 pub
·
2015-11-02 17:38
LeetCode
LeetCode题解
(7)--Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 思想:一个整数的倒序,没啥说的,在long类型上比较来避免overflow。 AC代码: 1 class Solution { 2 pub
·
2015-11-02 17:37
LeetCode
LeetCode题解
(8)--String to Integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the poss
·
2015-11-02 17:37
LeetCode
LeetCode题解
(6)--ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
·
2015-11-02 17:36
conversion
LeetCode题解
(3)-- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which t
·
2015-11-02 17:35
substring
LeetCode题解
(2)-- Add Two Numbers
原题: https://leetcode.com/problems/add-two-numbers/ You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes c
·
2015-11-02 17:35
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
上一页
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
其他