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
lintCode
python
Lintcode
刷题(一)
按难度或者通过率排序刷题我的代码如下:classSolution:#@paramn:aninteger#@returnanintegerf(n)deffibonacci(self,n):#writeyourcodeherea=0b=1foriinrange(n-1):a,b=b,a+breturna我的代码如下:classSolution:"""@paramn:Anintegerasdescrip
GeekLeee
·
2016-09-14 17:00
笔试
面试
刷题
概念
LintCode
144 [Interleaving Positive and Negative Numbers]
原题给出一个含有正整数和负整数的数组,重新排列成一个正负数交错的数组。样例给出数组[-1,-2,-3,4,5,6],重新排序之后,变成[-1,5,-2,4,-3,6]或者其他任何满足要求的答案解题思路扫第一遍,确定正数多还是负数多,多的放在0位partition数组,前面都是正数后面都睡负数,或者相反,根据谁多两步一跳,生成需要的正负间隔的数组完整代码classSolution:"""@param
Jason_Yuan
·
2016-09-06 10:25
LintCode
144 [Interleaving Positive and Negative Numbers]
原题给出一个含有正整数和负整数的数组,重新排列成一个正负数交错的数组。样例给出数组[-1,-2,-3,4,5,6],重新排序之后,变成[-1,5,-2,4,-3,6]或者其他任何满足要求的答案解题思路扫第一遍,确定正数多还是负数多,多的放在0位partition数组,前面都是正数后面都睡负数,或者相反,根据谁多两步一跳,生成需要的正负间隔的数组完整代码classSolution:"""@param
Jason_Yuan
·
2016-09-06 10:25
LintCode
(M)打劫房屋2——动态规划
思路:最后一次的状态方程为:i=nums.size()-1;//i为最后一家a[i]=max(houseRobber(A)+nums[i],houseRobber(B));说明:1.houseRobber(A)+nums[i]为抢最后一家的情况,A为{nums[1]….nums[i-2]}//少了第一家和最后两家。2.houseRobber(A)+nums[i]为不抢最后一家的情况,B为{nums
Jang1996
·
2016-08-30 21:47
LintCode
LintCode
(M)打劫房屋(动态规划)
最初代码:classSolution{public:/***@paramA:Anarrayofnon-negativeintegers.*return:Themaximumamountofmoneyyoucanrobtonight*/longlonghouseRobber(vectorA){//writeyourcodehere//intn=A.size();vectora(A.size(),0)
Jang1996
·
2016-08-30 15:57
LintCode
LintCode
(M)最小调整代价(待续)
最初有bug的代码:classSolution{public:/***@paramA:Anintegerarray.*@paramtarget:Aninteger.*/intMinAdjustmentCost(vectorA,inttarget){//writeyourcodehereintsum=0,i;floatp,q,w,ping=0;w=target;//target=(float)tar
Jang1996
·
2016-08-29 20:26
LintCode
Lintcode
68 二叉树的后序遍历
描述:给出一棵二叉树,返回其节点值的后序遍历。样例:给出一棵二叉树{1,#,2,3},返回[3,2,1]挑战:你能使用非递归实现么?代码:/***DefinitionofTreeNode:*classTreeNode{*public:*intval;*TreeNode*left,*right;*TreeNode(intval){*this->val=val;*this->left=this->ri
icesker
·
2016-08-28 18:39
二叉树
递归
遍历
Lintcode
Lintcode
67 二叉树的中序遍历
描述:给出一棵二叉树,返回其中序遍历样例:给出二叉树{1,#,2,3},返回[1,3,2].挑战:你能使用非递归算法来实现么?代码:/***DefinitionofTreeNode:*classTreeNode{*public:*intval;*TreeNode*left,*right;*TreeNode(intval){*this->val=val;*this->left=this->right
icesker
·
2016-08-28 18:20
Lintcode
Lintcode
66 二叉树的前序遍历
描述:给出一棵二叉树,返回其节点值的前序遍历。样例:给出一棵二叉树{1,#,2,3},返回[1,2,3].挑战:你能使用非递归实现么?代码:/***DefinitionofTreeNode:*classTreeNode{*public:*intval;*TreeNode*left,*right;*TreeNode(intval){*this->val=val;*this->left=this->r
icesker
·
2016-08-28 18:04
Lintcode
LintCode
(M)背包问题2
publicclassSolution{/***@paramm:Anintegermdenotesthesizeofabackpack*@paramA&V:GivennitemswithsizeA[i]andvalueV[i]*@return:Themaximumvalue*/publicintbackPackII(intm,int[]A,intV[]){//writeyourcodeherein
Jang1996
·
2016-08-27 15:13
LintCode
LintCode
(M)背包问题
以下代码为网上找的publicclassSolution{/***@paramm:Anintegermdenotesthesizeofabackpack*@paramA:GivennitemswithsizeA[i]*@return:Themaximumsize*/publicintbackPack(intm,int[]A){int[][]dp=newint[A.length][m+1];//动态
Jang1996
·
2016-08-26 16:01
LintCode
lintcode
打劫房屋
描述:假设你是一个专业的窃贼,准备沿着一条街打劫房屋。每个房子都存放着特定金额的钱。你面临的唯一约束条件是:相邻的房子装着相互联系的防盗系统,且当相邻的两个房子同一天被打劫时,该系统会自动报警。给定一个非负整数列表,表示每个房子中存放的钱,算一算,如果今晚去打劫,你最多可以得到多少钱在不触动报警装置的情况下。样例:给定[3,8,4],返回8.解题:本来认为奇偶相加判断大小就行了,实则不然,网上看到
laughitover
·
2016-08-18 14:13
lintcode
算法
单词切分(
LintCode
)
样例给出s="
lintcode
"dict=["lint","code"]返回true因为"
lintcode
"可以被空格切分成"
lintcode
"第一种DP算法,时间复杂度高classSolution{public
杰米
·
2016-08-17 01:32
[
LintCode
] Backpack I II III IV V VI [背包六问]
BackpackIProblem单次选择+最大体积GivennitemswithsizeAi,anintegermdenotesthesizeofabackpack.Howfullyoucanfillthisbackpack?NoticeYoucannotdivideanyitemintosmallpieces.ExampleIfwehave4itemswithsize[2,3,5,7],theb
linspiration
·
2016-08-15 00:00
背包问题
backpack
java
LintCode
(easy)合并排序数组II
classSolution{public:/***@paramA:sortedintegerarrayAwhichhasmelements,*butsizeofAism+n*@paramB:sortedintegerarrayBwhichhasnelements*@return:void*/voidmergeSortedArray(intA[],intm,intB[],intn){//writey
Jang1996
·
2016-08-08 10:11
LintCode
LintCode
(easy)合并排序数组
classSolution{public:/***@paramAandB:sortedintegerarrayAandB.*@return:Anewsortedintegerarray*/vectormergeSortedArray(vector&A,vector&B){//writeyourcodeherefor(autoc:A)B.push_back(c);sort(begin(B),end(
Jang1996
·
2016-08-08 09:14
LintCode
LintCode
465 [Kth Smallest Sum in Two Sorted Array]
原题给定两个排好序的数组A,B,定义集合sum=a+b,求sum中第k小的元素样例给出A=[1,7,11]B=[2,4,6]sum=[3,5,7,9,11,13,13,15,17]当k=3,返回7.当k=4,返回9.当k=8,返回15.解题思路使用set来记录访问过的pairvisited=set()visited.add(10)10isinvisited#returnTrue使用一个minHea
Jason_Yuan
·
2016-07-28 15:45
LeetCode 刷题指南(一):为什么要刷题
现在提供在线编程评测的平台有很多,比较有名的有hihocoder,
LintCode
,以及这里我们关注的LeetCode。
selfboot
·
2016-07-25 09:46
LeetCode 刷题指南(一):为什么要刷题
现在提供在线编程评测的平台有很多,比较有名的有hihocoder,
LintCode
,以及这里我们关注的LeetCode。
selfboot
·
2016-07-24 00:00
python2.7
c++
算法
LintCode
(easy)比较字符串(正确版)
classSolution{public:/***@paramA:AstringincludesUpperCaseletters*@paramB:AstringincludesUpperCaseletter*@return:ifstringAcontainsallofthecharactersinBreturntrue*elsereturnfalse*/boolcompareStrings(str
Jang1996
·
2016-07-22 14:17
LintCode
LintCode
(容易)55.比较字符串
需注意的点:1.字符串B中可能含有多个重复的大写字母,则A中此大写字母的个数至少要大于B中的个数。目前的思路:先把字符串A中26个字母的个数统计出来,按序存储在一个string型a里面,B同理,存储在string型b里面,然后直接比较a>b,true则包含。bug1:主要错误点:(一些小错点忽略)stringa应该为stringa(26,’0’);bug2:原因是:比如A(“ABCDEFG”),B
Jang1996
·
2016-07-22 09:09
LintCode
LintCode
398:判断数独是否合法
先判断行,再判断列。然后判断方格(!!!注意有九个方格)//判断方格代码。for(inti=0;i<9;i++){for(intj=0;j<9;j++){introw=j/3+i/3*3,intcol=j%3+i%3*3;cout<
Jang1996
·
2016-07-18 09:16
LintCode
LintCode
:接雨水
LintCode
:接雨水做法一:扫两遍。对某个值A[i]来说,能trapped的最多的water取决于在i之前左边的最高值和在i右边的最高的值,然后取当中较小的一个。
zyaphone
·
2016-07-14 00:28
lintcode
python
[
LintCode
] Reverse Nodes in k-Group 每k个一组翻转链表
Givenalinkedlist,reversethenodesofalinkedlistkatatimeandreturnitsmodifiedlist.Ifthenumberofnodesisnotamultipleofkthenleft-outnodesintheendshouldremainasitis.Youmaynotalterthevaluesinthenodes,onlynode
Grandyang
·
2016-07-10 09:00
LintCode
230 [Animal Shelter]
原题在一个宠物避难所里,仅有狗和猫两种动物可供领养,且领养时严格执行“先进先出”的规则。如果有人想要从避难所领养动物,他只有两种选择:要么选择领养所有动物中最资深的一只(根据到达避难所的时间,越早到的越资深),要么选择领养猫或狗(同样,也只能领养最资深的一只)。也就是说,领养者不能随意选择某一指定动物。请建立一个数据结构,使得它可以运行以上规则,并可实enqueue,dequeueAny,dequ
Jason_Yuan
·
2016-07-10 06:22
[
LintCode
/LeetCode] LRU Cache
ProblemDesignandimplementadatastructureforLeastRecentlyUsed(LRU)cache.Itshouldsupportthefollowingoperations:getandset.get(key)-Getthevalue(willalwaysbepositive)ofthekeyifthekeyexistsinthecache,otherwi
linspiration
·
2016-07-10 00:00
linkedhashmap
design-pattern
linkedlist
hashmap
java
[
LintCode
] Parking Lot 停车场问题
Designaparkinglot.seeCC150OODesignfordetails.1) n levels,eachlevelhas m rowsofspotsandeachrowhas k spots.Soeachlevelhas m x k spots.2)Theparkinglotcanparkmotorcycles,carsandbuses3)Theparkinglothasmot
Grandyang
·
2016-07-09 23:00
[
LintCode
] Swap Nodes in Pairs 成对交换节点
Givenalinkedlist,swapeverytwoadjacentnodesandreturnitshead. ExampleGiven1->2->3->4,youshouldreturnthelistas2->1->4->3.ChallengeYouralgorithmshoulduseonlyconstantspace.Youmaynotmodifythevaluesinthelis
Grandyang
·
2016-07-06 23:00
[
LintCode
] Remove Linked List Elements 移除链表元素
Removeallelementsfromalinkedlistofintegersthathavevalueval.Haveyoumetthisquestioninarealinterview? ExampleGiven1->2->3->3->4->5->3,val=3,youshouldreturnthelistas1->2->4->5 LeetCode上的原题,请参见我之前的博客Remo
Grandyang
·
2016-07-05 22:00
[
LintCode
] Flatten Binary Tree to Linked List 将二叉树展开成链表
Flattenabinarytreetoafake"linkedlist"inpre-ordertraversal.HereweusetherightpointerinTreeNodeasthenextpointerinListNode.NoticeDon'tforgettomarktheleftchildofeachnodetonull.OryouwillgetTimeLimitExceede
Grandyang
·
2016-07-04 23:00
[
LintCode
] Sort Integers II 整数排序之二
Givenanintegerarray,sortitinascendingorder.Usequicksort,mergesort,heapsortoranyO(nlogn)algorithm. ExampleGiven [3,2,1,4,5],return [1,2,3,4,5]. 解法一://Quicksort classSolution{ public: /** *@param
Grandyang
·
2016-07-03 12:00
[
LintCode
] Sort Integers 整数排序
Givenanintegerarray,sortitinascendingorder.Useselectionsort,bubblesort,insertionsortoranyO(n2)algorithm. ExampleGiven[3,2,1,4,5],return[1,2,3,4,5]. 这道题让我们实现最基本的几个O(n2)的排序算法,选择排序,冒泡排序和插入排序,都是最基本的排序算法。
Grandyang
·
2016-07-02 12:00
LintCode
128 [Hash Function]
原题在数据结构中,哈希函数是用来将一个字符串(或任何其他类型)转化为小于哈希表大小且大于等于零的整数。一个好的哈希函数可以尽可能少地产生冲突。一种广泛使用的哈希函数算法是使用数值33,假设任何字符串都是基于33的一个大整数。给出一个字符串作为key和一个哈希表的大小,返回这个字符串的哈希值。对于key="abcd"并且size=100,返回78解题思路:关于哈希表:哈希表在内存中是一个事先开辟好的
Jason_Yuan
·
2016-06-26 14:34
[
LintCode
] Identical Binary Tree 相同二叉树
Checkiftwobinarytreesareidentical.Identicalmeansthetwobinarytreeshavethesamestructureandeveryidenticalpositionhasthesamevalue.Haveyoumetthisquestioninarealinterview? Example11 /\/\ 22and22 // 44
Grandyang
·
2016-06-20 13:00
[
LintCode
] Create Maximum Number 创建最大数
Giventwoarraysoflengthmandnwithdigits0-9representingtwonumbers.CreatethemaximumnumberoflengthkmaxNumber(vector&nums1,vector&nums2,intk){ vectorres; intm=nums1.size(),n=nums2.size(); for(inti=max(0
Grandyang
·
2016-06-16 23:00
LintCode
217 [Remove Duplicates from Unsorted List]
原题设计一种方法,从无序链表中删除重复项。样例给出1->3->2->1->4.�返回1->3->2->4解题思路遍历链表,用一hash表记录出现过的节点的值,如果出现过则删除,未出现过则加入hash表完整代码"""DefinitionofListNodeclassListNode(object):def__init__(self,val,next=None):self.val=valself.ne
Jason_Yuan
·
2016-06-12 13:30
LintCode
(103)带环链表 II
题目给定一个链表,如果链表中存在环,则返回到链表中环的起始节点的值,如果没有环,返回null。您在真实的面试中是否遇到过这个题?Yes样例给出-21->10->4->5,tailconnectstonodeindex1,返回10分析上一题的进阶。首先,利用快慢指针判断有无环,若遇到slow==fast时,跳出循环;然后,调整fast=head,slow不变,此时slow与fast同步移动,直至再次
逆風的薔薇
·
2016-05-31 21:26
LeetCode
&
LintCode
LintCode
(103)带环链表 II
题目给定一个链表,如果链表中存在环,则返回到链表中环的起始节点的值,如果没有环,返回null。您在真实的面试中是否遇到过这个题? Yes样例给出 -21->10->4->5,tailconnectstonodeindex1,返回10分析上一题的进阶。首先,利用快慢指针判断有无环,若遇到slow==fast时,跳出循环;然后,调整fast=head,slow不变,此时slow与fast同步移动,直至
fly_yr
·
2016-05-31 21:00
LintCode
(102) 带环链表
题目给定一个链表,判断它是否有环。您在真实的面试中是否遇到过这个题? Yes样例给出 -21->10->4->5,tailconnectstonodeindex1,返回true分析判断链表有无环的问题,很经典,也是面试中常见的问题。快慢指针解决。Python代码""" DefinitionofListNode classListNode(object): def__init__(self,val
fly_yr
·
2016-05-31 20:00
C++
python
lintcode
LintCode
(101)删除排序数组中的重复数字 II
题目跟进“删除重复数字”:如果可以允许出现两次重复将如何处理?您在真实的面试中是否遇到过这个题? Yes样例给出数组A=[1,1,1,2,2,3],你的函数应该返回长度5,此时A=[1,1,2,2,3]。分析与上题思路相同,只需要增加一个记录元素出现次数的变量即可,限制最多出现2次。Python代码classSolution: """ @paramA:alistofintegers @return
fly_yr
·
2016-05-31 20:00
II
101
lintcode
删除排序数组中的重复数字
LintCode
(100)删除排序数组中的重复数字
题目给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度。不要使用额外的数组空间,必须在原地没有额外空间的条件下完成。您在真实的面试中是否遇到过这个题? Yes样例给出数组A=[1,1,2],你的函数应该返回长度2,此时A=[1,2]。分析对排序数组去重,要求空间复杂度为O(1)遍历一次数组,将不重复元素保留,重复元素被覆盖,最后删除末尾剩余的元素即可。P
fly_yr
·
2016-05-31 20:00
LintCode
(56) 两数之和
题目给一个整数数组,找到两个数使得他们的和等于一个给定的数target。你需要实现的函数twoSum需要返回这两个数的下标,并且第一个下标小于第二个下标。注意这里下标的范围是1到n,不是以0开头。注意事项你可以假设只有一组答案。您在真实的面试中是否遇到过这个题?Yes样例给出numbers=[2,7,11,15],target=9,返回[1,2].分析相对较简单的题目,两层循环即可。Python代
逆風的薔薇
·
2016-05-31 10:23
LeetCode
&
LintCode
LintCode
(56) 两数之和
题目给一个整数数组,找到两个数使得他们的和等于一个给定的数 target。你需要实现的函数twoSum需要返回这两个数的下标,并且第一个下标小于第二个下标。注意这里下标的范围是1到 n,不是以 0 开头。 注意事项你可以假设只有一组答案。您在真实的面试中是否遇到过这个题? Yes样例给出numbers= [2,7,11,15],target= 9,返回 [1,2].分析相对较简单的题目,两层循环即
fly_yr
·
2016-05-31 10:00
C++
python
lintcode
56.两数之和
[
LintCode
] Move Zeroes 移动零
Givenanarraynums,writeafunctiontomoveall0'stotheendofitwhilemaintainingtherelativeorderofthenon-zeroelements.NoticeYoumustdothisin-placewithoutmakingacopyofthearray.Minimizethetotalnumberofoperations
Grandyang
·
2016-05-31 00:00
LintCode
470 [Tweaked Identical Binary Tree]
原题检查两棵二叉树是否在经过若干次扭转后可以等价。扭转的定义是,交换任意节点的左右子树。等价的定义是,两棵二叉树必须为相同的结构,并且对应位置上的节点的值要相等。注意:你可以假设二叉树中不会有重复的节点值。样例11/\/\23and32/\44是扭转后可等价的二叉树。11/\/\23and32//44就不是扭转后可以等价的二叉树。解题思路Recursion-递归求解,分治的思路。注意,题目中说的是
Jason_Yuan
·
2016-05-28 16:21
一定要啃掉
刚才一直在研究课上的那几道dp问题,
lintcode
上标注为中等难度,到了leetcode上才发现,全是hard,但这个骨头现在我们一定要啃,拨出两天,一定要啃掉!
sjphiChina
·
2016-05-23 18:31
随笔
[
LintCode
] Shape Factory 形状工厂
Factoryisadesignpatternincommonusage.ImplementaShapeFactorythatcangeneratecorrectshape. Youcanassumethatwehaveonlytreedifferentshapes:Triangle,SquareandRectangle. Example ShapeFactorysf=newShapeFa
Grandyang
·
2016-05-20 15:00
lintcode
算法周竞赛
------------------------------------------------------------第七周:Followupquestion1,寻找峰值寻找峰值描述笔记数据评测你给出一个整数数组(size为n),其具有以下特点:相邻位置的数字是不同的A[0]A[n-1]假定P是峰值的位置则满足A[P]>A[P-1]且A[P]>A[P+1],返回数组中任意一个峰值的位置。注意事项
weixin_34336292
·
2016-05-20 08:00
面试
java
数据结构与算法
LintCode
460 [ K Closest Numbers In Sorted Array]
原题给一个目标数target,一个非负整数k,一个按照升序排列的数组A。在A中找与target最接近的k个整数。返回这k个数并按照与target的接近程度从小到大排序,如果接近程度相当,那么小的数排在前面。如果A=[1,2,3],target=2andk=3,那么返回[2,1,3]如果A=[1,4,6,8],target=3andk=3,那么返回[4,1,6]解题思路使用BinarySearch找
Jason_Yuan
·
2016-05-19 16:45
[
LintCode
] Mini Twitter 迷你推特
Implementasimpletwitter.Supportthefollowingmethod:postTweet(user_id,tweet_text).Postatweet.getTimeline(user_id).Getthegivenuser'smostrecently10tweetspostedbyhimself,orderbytimestampfrommostrecenttole
Grandyang
·
2016-05-19 07:00
上一页
67
68
69
70
71
72
73
74
下一页
按字母分类:
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
其他