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题解
: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
leetcode资料整理
https://github.com/soulmachine/leetcode https://github.com/soulmachine/leetcode/tree/master (
LeetCode
·
2015-06-03 20:00
LeetCode
LeetCode 汇总
LeetCode汇总
LeetCode题解
https://github.com/soulmachine/leetcode
LeetCode题解
(C++版).pdfhttps://github.com/soulmachine
JUST DO IT ~
·
2015-04-20 14:00
leetcode题解
|| Roman to Integer问题
problem:Givenaromannumeral,convertittoaninteger. Inputisguaranteedtobewithintherangefrom1to3999.将罗马数字转为整数thinking:(1)罗马数字规则:罗马数字共有7个,即I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和M(1000)。按照下述的规则可以表示任意正整数。需要注意
hustyangju
·
2015-03-18 16:00
LeetCode
map
罗马数字
leetcode题解
||Integer to Roman问题
problem:Givenaninteger,convertittoaromannumeral. Inputisguaranteedtobewithintherangefrom1to3999.将1-3999的整数转换为罗马数字thinking:(1)对照举例个位数举例Ⅰ,1】Ⅱ,2】Ⅲ,3】Ⅳ,4】Ⅴ,5】Ⅵ,6】Ⅶ,7】Ⅷ,8】Ⅸ,9】十位数举例Ⅹ,10】Ⅺ,11】Ⅻ,12】XIII,13】X
hustyangju
·
2015-03-18 16:00
LeetCode
罗马数字
leetcode题解
||Container With Most Water问题
problem:Givennnon-negativeintegersa1,a2,...,an,whereeachrepresentsapointatcoordinate(i,ai). nverticallinesaredrawnsuchthatthetwoendpointsoflineiisat(i,ai)and(i,0). Findtwolines,whichtogetherwithx-axis
hustyangju
·
2015-03-18 15:00
遍历
双指针
leetcode题解
||Regular Expression Matching 问题
problem:Implementregularexpressionmatchingwithsupportfor'.'and'*'. '.'Matchesanysinglecharacter. '*'Matcheszeroormoreoftheprecedingelement. Thematchingshouldcovertheentireinputstring(notpartial). T
hustyangju
·
2015-03-18 11:00
dp
模式识别
leetcode题解
||Palindrome Number问题
problem:Determinewhetheranintegerisapalindrome.Dothiswithoutextraspace. clicktoshowspoilers. Somehints: Couldnegativeintegersbepalindromes?(ie,-1) Ifyouarethinkingofconvertingtheintegertostring,not
hustyangju
·
2015-03-17 20:00
回文数
int反转
leetcode题解
||Reverse Integer 问题
problem:Reversedigitsofaninteger. Example1:x=123,return321 Example2:x=-123,return-321thinking:(1)整型反转直观很容易理解。如正负,尾数为0等问题还好处理。(2)反转溢出问题要仔细处理。code:classSolution{ public: intreverse(intx){ longlonginty=
hustyangju
·
2015-03-17 16:00
LeetCode
溢出
int反转
leetcode题解
||ZigZag Conversion问题
problem:Thestring"PAYPALISHIRING"iswritteninazigzagpatternonagivennumber ofrowslikethis: (youmaywanttodisplaythispatterninafixedfontforbetterlegibility) PAHN APLSIIG YIR Andthenreadlinebyline:"PAHNAP
hustyangju
·
2015-03-17 14:00
LeetCode
字符串
String
leetcode题解
||Median of Two Sorted Arrays问题
problem:TherearetwosortedarraysAandBofsizemandnrespectively. Findthemedianofthetwosortedarrays. TheoverallruntimecomplexityshouldbeO(log(m+n)).thinking:(1)求中位数,就是求已序数列的中间位置对应的数字,分奇偶。两个已序数组求中位数,就是求合并后的
hustyangju
·
2015-03-16 19:00
分治
合并排序
递归算法
第K大数字
LeetCode题解
|| Longest Substring Without Repeating Characters (O(n)算法)问题
problem:Givenastring,findthelengthofthelongestsubstringwithoutrepeatingcharacters. Forexample,thelongestsubstringwithoutrepeatinglettersfor"abcabcbb"is"abc", whichthelengthis3.For"bbbbb"thelongestsubs
hustyangju
·
2015-03-16 15:00
算法
table
hash
substring
[LeetCode] 037. Sudoku Solver (Hard) (C++)
索引:[LeetCode]
Leetcode题解
索引(C++/Java/Python/Sql)Github:https://github.com/illuz/leetcode037.SudokuSolver
hcbbt
·
2015-03-13 19:00
LeetCode
C++
算法
[LeetCode] 036. Valid Sudoku (Easy) (C++)
索引:[LeetCode]
Leetcode题解
索引(C++/Java/Python/Sql)Github:https://github.com/illuz/leetcode036.ValidSudoku
hcbbt
·
2015-03-13 19:00
LeetCode
C++
算法
[LeetCode] 035. Search Insert Position (Medium) (C++)
索引:[LeetCode]
Leetcode题解
索引(C++/Java/Python/Sql)Github:https://github.com/illuz/leetcode035.SearchInsertPosition
hcbbt
·
2015-03-13 18:00
LeetCode
C++
算法
[LeetCode] 034. Search for a Range (Medium) (C++/Java)
索引:[LeetCode]
Leetcode题解
索引(C++/Java/Python/Sql)Github:https://github.com/illuz/leetcode035.SearchforaRange
hcbbt
·
2015-03-13 18:00
java
LeetCode
C++
算法
上一页
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
其他