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
CC150
CC150
8.2
8.2 ImaginearobotsittingontheupperlefthandcornerofanNxNgrid.Therobotcanonlymoveintwodirections:rightanddown.Howmanypossiblepathsaretherefortherobot?FOLLOWUPImaginecertainsquaresare“offlimits”,suchthat
furuijie8679
·
2014-12-01 05:49
interview
学习资料
创新不论处于什么阶段都要坚持学习,善于发掘深层的原因,发现有趣的东西http://www.csie.ntnu.edu.tw/~u91029/ 台湾UVA题库http://www.leetcode.com/ 北美OJ130道题目
cc150
doupei2006
·
2014-11-30 17:00
cc150
:使用两个栈实现一个队列(两种方法比较)
队列是先进先出的数据结构(FIFO),栈是先进后出的数据结构(FILO),用两个栈来实现队列的最简单方式是:进入队列则往第一个栈压栈,出队列则将第一个栈的数据依次压入第二个栈,然后出栈。每次有数据进入队列,都先将第二个栈的数据压回第一个栈,然后再压入新增的那个数据;每次有数据出队列,都将第一个栈的数据压入第二个栈,然后第二个栈出栈。代码很简单:template classMyQueue{ pu
u010893129
·
2014-11-30 01:00
栈
队列
cc150
:使用栈来实现汉诺塔
递归解法其实也是用到了栈的,在每次递归调用自己的时候,将中间的状态参数压入栈中。不过这些操作都是系统隐式进行的,所以你不用去关心它具体是怎么压栈出栈的。如果我们要用栈自己来实现这个过程,就不得不考虑这其中的细节了。 接下来,我们就显式地用栈来实现递归过程中,这些状态参数的压栈出栈过程。首先,我们需要定义一个数据结构来保存操作过程中的参数。structop{ intbegin,end;
u010893129
·
2014-11-30 01:00
栈
汉诺塔
cc150
CC150
8.1
8.1 WriteamethodtogeneratethenthFibonaccinumber.class Fibonacci() { void init() { a = 0; b = 1; } int next() { int toReturn = a + b; a = b; b = toReturn; return to
furuijie8679
·
2014-11-28 08:43
interview
CC150
4.7
4.7 Youhavetwoverylargebinarytrees:T1,withmillionsofnodes,andT2,withhundredsofnodes.CreateanalgorithmtodecideifT2isasubtreeofT1.// It will iterate main tree (millions) nodes. // Too bad. boolean isSub
furuijie8679
·
2014-11-28 08:43
interview
CC150
4.6
4.6 Designanalgorithmandwritecodetofindthefirstcommonancestoroftwonodesinabinarytree.Avoidstoringadditionalnodesinadatastructure.NOTE:Thisisnotnecessarilyabinarysearchtree.BTNode find(Node n, Node a,
furuijie8679
·
2014-11-27 06:59
interview
CC150
4.5
4.5 Writeanalgorithmtofindthe‘next’node(i.e.,in-ordersuccessor)ofagivennodeinabinarysearchtreewhereeachnodehasalinktoitsparent.// BST. class Node { Node parent; Node left; Node right; } Node m
furuijie8679
·
2014-11-27 06:59
interview
CC150
4.4
4.4 Givenabinarysearchtree,designanalgorithmwhichcreatesalinkedlistofallthenodesateachdepth(i.e.,ifyouhaveatreewithdepthD,you’llhaveDlinkedlists).List> build(Node root) { List> toReturn = initList()
furuijie8679
·
2014-11-27 06:41
interview
CC150
4.3
4.3 Givenasorted(increasingorder)array,writeanalgorithmtocreateabinarytreewithminimalheight.[1,2,4,5,6]CreateaBTwithminheight.=>balancedtree.Node build(int array) { return build(array, 0, array.leng
furuijie8679
·
2014-11-27 06:50
interview
CC150
4.2
4.2 Givenadirectedgraph,designanalgorithmtofindoutwhetherthereisaroutebetweentwonodes.Node { List neighbours; } boolean isConnected(Node from, Node to) { Stack toVisit = initStack(); Set seen =
furuijie8679
·
2014-11-27 06:15
interview
CC150
4.1
4.1 Implementafunctiontocheckifatreeisbalanced.Forthepurposesofthisquestion,abalancedtreeisdefinedtobeatreesuchthatnotwoleafnodesdifferindistancefromtherootbymorethanone.Abalancedtree?http://en.wikipe
furuijie8679
·
2014-11-27 05:52
interview
CC150
3.6
3.6 Writeaprogramtosortastackinascendingorder.Youshouldnotmakeanyassumptionsabouthowthestackisimplemented.Thefollowingaretheonlyfunctionsthatshouldbeusedtowritethisprogram:push|pop|peek|isEmpty.interf
furuijie8679
·
2014-11-27 05:16
interview
CC150
3.5
3.5 ImplementaMyQueueclasswhichimplementsaqueueusingtwostacks.interface Queue { enqueue(T t); T dequeue(); } class MyQueue implements Queue { MyQueue() { // Init stacks s1 and s2; ...
furuijie8679
·
2014-11-27 05:47
interview
CC150
3.4
3.4 IntheclassicproblemoftheTowersofHanoi,youhave3rodsandNdisksofdifferentsizeswhichcanslideontoanytower.Thepuzzlestartswithdiskssortedinascendingorderofsizefromtoptobottom(e.g.,eachdisksitsontopofane
furuijie8679
·
2014-11-25 00:01
interview
CC150
3.3
3.3 Imaginea(literal)stackofplates.Ifthestackgetstoohigh,itmighttopple.Therefore,inreallife,wewouldlikelystartanewstackwhenthepreviousstackexceedssomethreshold.ImplementadatastructureSetOfStacksthatmi
furuijie8679
·
2014-11-25 00:00
interview
CC150
3.2
3.2 Howwouldyoudesignastackwhich,inadditiontopushandpop,alsohasafunctionminwhichreturnstheminimumelement?Push,popandminshouldalloperateinO(1)time.Useanotherstackmaintainingmin. push(T t) { mainStack
furuijie8679
·
2014-11-24 08:49
interview
CC150
3.1
3.1 Describehowyoucoulduseasinglearraytoimplementthreestacks.3stacks?separatethearrayinto3sections.Use3index.push(int stack, T t) { validateStackNum(stack); // Validate(stack >= 0 && stack < 2);
furuijie8679
·
2014-11-24 08:29
interview
CC150
2.5
2.5 Givenacircularlinkedlist,implementanalgorithmwhichreturnsnodeatthebeginningoftheloop.DEFINITIONCircularlinkedlist:A(corrupt)linkedlistinwhichanode’snextpointerpointstoanearliernode,soastomakealoop
furuijie8679
·
2014-11-24 08:36
interview
CC150
2.4
2.4 Youhavetwonumbersrepresentedbyalinkedlist,whereeachnodecontainsasingledigit.Thedigitsarestoredinreverseorder,suchthatthe1’sdigitisattheheadofthelist.Writeafunctionthataddsthetwonumbersandreturnsth
furuijie8679
·
2014-11-24 07:27
interview
CC150
2.3
2.3 Implementanalgorithmtodeleteanodeinthemiddleofasinglelinkedlist,givenonlyaccesstothatnode.EXAMPLEInput:thenode‘c’fromthelinkedlista->b->c->d->eResult:nothingisreturned,butthenewlinkedlistlookslike
furuijie8679
·
2014-11-24 07:14
interview
CC150
2.2
2.2 Implementanalgorithmtofindthenthtolastelementofasinglylinkedlist.// Assume the input list has no circle. // O(n) Node findNthNodeToLast(Node root, int n) { // Find size Node n = root; int si
furuijie8679
·
2014-11-24 07:59
interview
CC150
2.1
2.1 Writecodetoremoveduplicatesfromanunsortedlinkedlist.FOLLOWUPHowwouldyousolvethisproblemifatemporarybufferisnotallowed?Iftempbufferallowed,usingmap.Ifnot,foreachnode,removealldupsafterthis.void rem
furuijie8679
·
2014-11-23 05:37
interview
CC150
1.8
1.8 AssumeyouhaveamethodisSubstringwhichchecksifonewordisasubstringofanother.Giventwostrings,s1ands2,writecodetocheckifs2isarotationofs1usingonlyonecalltoisSubstring(i.e.,“waterbottle”isarotationof“er
furuijie8679
·
2014-11-23 04:21
interview
CC150
1.1
1.7 WriteanalgorithmsuchthatifanelementinanMxNmatrixis0,itsentirerowandcolumnissetto0.Copytoanewmatrix.Oreachelementneedtostoreabooleanflagindicatingwhetherthiselementshouldbe0ornot.// Copy int[][] cl
furuijie8679
·
2014-11-23 04:11
interview
CC150
1.6
1.6 GivenanimagerepresentedbyanNxNmatrix,whereeachpixelintheimageis4bytes,writeamethodtorotatetheimageby90degrees.Canyoudothisinplace?Defineapixel.class Pixel { Byte[] data; // a 4 bytes }// From //
furuijie8679
·
2014-11-23 04:10
interview
CC150
1.5
1.5 Writeamethodtoreplaceallspacesinastringwith‘%20’.string.replace(" ", "%20"); ?? // Manipulating chars. String replaceSpaces(String s) { if (s == null) return null; char[] chars = s.t
furuijie8679
·
2014-11-23 03:00
interview
CC150
1.4
1.4 Writeamethodtodecideiftwostringsareanagramsornot.Whatisanagrams?See http://en.wikipedia.org/wiki/AnagramTrueiftwostringscontainssamesetofchars// Using map to store char occurance. boolean isAnagr
furuijie8679
·
2014-11-23 03:01
interview
CC150
1.4
1.4Writeamethodtodecideiftwostringsareanagramsornot.Whatisanagrams?Seehttp://en.wikipedia.org/wiki/AnagramTrueiftwostringscontainssamesetofchars// Using map to store char occurance.boolean isAnagrams(
furuijie8679
·
2014-11-23 03:01
interview
Interview
CC150
1.3
1.3 Designanalgorithmandwritecodetoremovetheduplicatecharactersinastringwithoutusinganyadditionalbuffer.NOTE:Oneortwoadditionalvariablesarefine.Anextracopyofthearrayisnot.FOLLOWUPWritethetestcasesfort
furuijie8679
·
2014-11-23 03:05
interview
CC150
1.2
See 1.2 WritecodetoreverseaC-StyleString.(C-Stringmeansthat“abcd”isrepresentedasfivecharacters,includingthenullcharacter.)Iamnotfamiliarwith"C-StyleString".Whereisthenullchar?intheend?orinthebeginning
furuijie8679
·
2014-11-23 03:46
interview
CC150
1.1
OK.Let'sstarted.Question:1.1 Implementanalgorithmtodetermineifastringhasalluniquecharacters.Whatifyoucannotuseadditionaldatastructures?// Using a set tracking each char // O(n) for time. Need O(n) for
furuijie8679
·
2014-11-23 03:28
interview
cc150
:实现一个栈,除了push和pop操作,还要实现min函数以返回栈中的最小值。
实现一个栈,除了push和pop操作,还要实现min函数以返回栈中的最小值。push,pop和min函数的时间复杂度都为O(1)。 我们可以用一个变量来保存当前栈的最小值,让我们来看看这样可行否?如果栈一直push那是没有问题,入栈元素如果比当前最小值还小,那就更新当前最小值。可是如果pop掉的栈顶元素就是最小值,那么我们如何更新最小值呢?显然不太好办。既然只用一个变量没法解决这个问题,
u010893129
·
2014-11-18 01:00
栈
cc150
cc150
:使用一个数组实现3个栈
你如何只用一个数组实现三个栈? 很容易地用一个数组来实现一个栈,压栈就往数组里插入值,栈顶指针加1;出栈就直接将栈顶指针减1;取栈顶值就把栈顶指针指向的单元的值返回;判断是否为空就直接看栈顶指针是否为-1。如果要在一个数组里实现3个栈,可以将该数组分为3个部分。如果我们并不知道哪个栈将装入更多的数据,就直接将这个数组平均分为3个部分,每个部分维护一个栈顶指针,根据具体是对哪个栈进行
u010893129
·
2014-11-18 01:00
类
数据
栈
结构
cc150
[leetcode] Anagrams
returnallgroupsofstringsthatareanagrams.Note:Allinputswillbeinlower-case.https://oj.leetcode.com/problems/anagrams/思路:anagram的题目,
CC150
jdflyfly
·
2014-06-26 11:00
java
LeetCode
String
hash
Anagrams -- LeetCode
原题链接: http://oj.leetcode.com/problems/anagrams/ 这是一道很经典的面试题了,在
cc150
里面也有,就是把一个数组按照易位构词分类。
linhuanmars
·
2014-03-21 01:00
java
LeetCode
排序
面试
HashMap
Linked List Cycle -- LeetCode
原题链接: http://oj.leetcode.com/problems/linked-list-cycle/ 这道题是
cc150
里面的题目,算是链表里面比较经典的题目。
linhuanmars
·
2014-03-19 04:00
java
LeetCode
算法
面试
链表
ZigZag Conversion -- LeetCode
原题链接: http://oj.leetcode.com/problems/zigzag-conversion/ 这道题是
cc150
里面的题目了,其实比较简单,只要看出来他其实每个zigzag是2*m-
linhuanmars
·
2014-03-15 06:00
java
LeetCode
算法
面试
数组
Add Two Numbers -- LeetCode
原题链接: http://oj.leetcode.com/problems/add-two-numbers/ 这道题比较简单,是
cc150
里面的题,思路很明确,就是按照位数读下去,维护当前位和进位,时间复杂度是
linhuanmars
·
2014-02-26 06:00
java
LeetCode
算法
面试
面向对象
递归与非递归法实现链表相加
CC150
V5 2.5题 java版
前言:这是一道很有意思的题目,原题如下:Youhavetwonumbersrepresentedbyalinkedlist,whereeachnodecontainsasingledigit.Thedigitsarestoredinreverseorder,suchthatthe1’sdigitisattheheadofthelist.Writeafunctionthataddsthetwonum
JamesDing1987
·
2014-01-08 04:39
java
链表
2.5
加法
cc150
Android自定义Style实现方法
styles.xml如下:[html]复制代码代码如下:30px#1110
CC150
dip150dipmain.xml如下:[html]复制代码代码如下:MainActivity如下:[java]复制代码代码如下
·
2013-06-05 09:48
[
cc150
] 1.1
1.1Implementanalgorithmtodetermineifastringhasalluniquecharacters.Whatifyoucannotuseadditionaldatastructure?1.假定input只有‘a’~‘z’这26个字母,开个最naive的hash就可以了classSolution{ public: boolisUniqueChars2(stringst
tuantuanls
·
2013-03-17 13:00
cc150
[
cc150
] 1.2
1.2WritecodetoreverseaC-StyleString.classSolution{ public: voidreverse(char*str){ if(!*str)return; char*p=str,*q=str; while(*q)q++; q--; chartmp; while(p
tuantuanls
·
2013-03-17 13:00
cc150
[
cc150
] 1.3
Designanalgorithmandwritecodetoremovetheduplicatecharactersinastringwithoutusinganyadditionalbuffer.NOTE:Oneortwoadditionalvariablesarefine.Anextracopyofthearrayisnot.FOLLOWUPWritethetestcasesforthism
tuantuanls
·
2013-03-17 13:00
cc150
[
cc150
] 1.4
Writeamethodtodecideiftwostringsareanagramsornotleetcode上面anagramstring的简化版1.排序2.用一个cnt来计算每个出现的个数没啥好写的。。。
tuantuanls
·
2013-03-17 13:00
cc150
[
cc150
] 2.5
2.5Givenacircularlinkedlist,implementanalgorithmwhichreturnsnodeatthebeginningoftheloop.Input:A->B->C->D->E->C(thesameCasearlier)Output:C介个题目代表了一类有环链表的问题。思路比较固定啦~~一个很老的题目就是判断两个链表是否有环,答案就是两个指针,第一个每次走一步
tuantuanls
·
2013-03-17 13:00
cc150
[
cc150
] 3.1
3.1Describehowyoucoulduseasinglearraytoimplementthreestacks.如果维护2个stack还可以左边一个,右边一个,现在维护3个啊!焚蛋,肿么办?!答案里面说可以改数组,数组里面的每个node保留着当前stack的上一个index。这样每次push的时候,顺序的在数组里面放就可以了。还有一个很大的问题就是pop,当有stackpop的时候,就会
tuantuanls
·
2013-03-17 13:00
cc150
[
cc150
] 3.1
3.1Describehowyoucoulduseasinglearraytoimplementthreestacks.如果维护2个stack还可以左边一个,右边一个,现在维护3个啊!焚蛋,肿么办?!答案里面说可以改数组,数组里面的每个node保留着当前stack的上一个index。这样每次push的时候,顺序的在数组里面放就可以了。还有一个很大的问题就是pop,当有stackpop的时候,就会
tuantuanls
·
2013-03-15 22:54
cc150
[
cc150
] 2.5
2.5Givenacircularlinkedlist,implementanalgorithmwhichreturnsnodeatthebeginningoftheloop.Input:A->B->C->D->E->C(thesameCasearlier)Output:C介个题目代表了一类有环链表的问题。思路比较固定啦~~一个很老的题目就是判断两个链表是否有环,答案就是两个指针,第一个每次走一
tuantuanls
·
2013-03-15 16:17
cc150
[
cc150
] 1.4
Writeamethodtodecideiftwostringsareanagramsornotleetcode上面anagramstring的简化版1.排序2.用一个cnt来计算每个出现的个数没啥好写的。。。
tuantuanls
·
2013-03-15 10:24
cc150
上一页
1
2
3
4
下一页
按字母分类:
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
其他