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
二叉树的前序、中序、后续遍历
LintCode
也有相关的题目,翻转二叉树。
chan15
·
2015-09-25 20:00
算法
遍历
二叉树
lintcode
-x的平方根-141
classSolution{ public: intsqrt(intx){ intleft=0,right=x/2; longlongmid=0; while(leftcur) returnmid; elseif(cur>x) right=mid-1; else left=mid+1; } return1; } };
ljlstart
·
2015-09-25 15:00
lintcode
-区间求和I-206
/** *DefinitionofInterval: *publicclasssInterval{ *intstart,end; *Interval(intstart,intend){ *this.start=start; *this.end=end; *} */ classSegmentTreeNode{ publicintstart,end; publiclongsum; publicSegm
ljlstart
·
2015-09-25 14:00
lintcode
-二叉树的层次遍历II-70
给出一棵二叉树,返回其节点值从底向上的层次序遍历(按从叶节点所在层到根节点所在的层遍历,然后逐层从左往右遍历)样例给出一棵二叉树 {3,9,20,#,#,15,7},3 /\ 920 /\ 157按照从下往上的层次遍历为:[ [15,7], [9,20], [3] ] /** *DefinitionofTreeNode: *classTreeNode{ *public: *intval; *
ljlstart
·
2015-09-25 14:00
lintcode
-区间最小数-205
classSegmentTreeNode{ publicintstart,end,min; publicSegmentTreeNodeleft,right; publicSegmentTreeNode(intstart,intend){ this.start=start; this.end=end; this.min=0; this.left=this.right=null; } } public
ljlstart
·
2015-09-25 13:00
lintcode
-线段树查询II-247
/*classSegmentTreeNode{ *public: *intstart,end,count; *SegmentTreeNode*left,*right; *SegmentTreeNode(intstart,intend,intcount){ *this->start=start; *this->end=end; *this->count=count; *this->left=this
ljlstart
·
2015-09-24 22:00
lintcode
-线段树的修改-203
/** *DefinitionofSegmentTreeNode: *classSegmentTreeNode{ *public: *intstart,end,max; *SegmentTreeNode*left,*right; *SegmentTreeNode(intstart,intend,intmax){ *this->start=start; *this->end=end; *this->
ljlstart
·
2015-09-24 21:00
lintcode
-线段树的查询-202
/** *DefinitionofSegmentTreeNode: *classSegmentTreeNode{ *public: *intstart,end,max; *SegmentTreeNode*left,*right; *SegmentTreeNode(intstart,intend,intmax){ *this->start=start; *this->end=end; *this->
ljlstart
·
2015-09-24 21:00
lintcode
-线段树的构造-201
/** *DefinitionofSegmentTreeNode: *classSegmentTreeNode{ *public: *intstart,end; *SegmentTreeNode*left,*right; *SegmentTreeNode(intstart,intend){ *this->start=start,this->end=end; *this->left=this->ri
ljlstart
·
2015-09-24 21:00
lintcode
-Segmemt Tree Build II-439
/** *DefinitionofSegmentTreeNode: *classSegmentTreeNode{ *public: *intstart,end,max; *SegmentTreeNode*left,*right; *SegmentTreeNode(intstart,intend,intmax){ *this->start=start; *this->end=end; *this->
ljlstart
·
2015-09-24 21:00
LintCode
-- 最长上升子序列 O(nlgn)
LintCode
-- longest-increasing-subsequence(最长上升子序列)原题链接:http://www.
lintcode
.com/zh-cn/problem/longest-increasing-subsequence
chan15
·
2015-09-24 15:00
算法
lintcode
【
Lintcode
|leetcode】245 Subtree
/***DefinitionofTreeNode: *classTreeNode{ *public: *intval; *TreeNode*left,*right; *TreeNode(intval){ *this->val=val; *this->left=this->right=NULL; *} *} */ classSolution{ public: /** *@paramT1,T2:The
JANESTAR
·
2015-09-23 00:00
LeetCode
lintcode
lintcode
-奇偶分割数组-373
classSolution{ public: voidpartitionArray(vector&nums){ intmid=-1; for(auto&e:nums){ if(e&1) swap(e,nums[++mid]); } } };
ljlstart
·
2015-09-22 22:00
lintcode
-最长上升连续子序列-397
classSolution{ public: intlongestIncreasingContinuousSubsequence(vector&A){ constintn=A.size(); if(0==n) return0; if(1==n) return1; intrdp[n],rmax=0,ldp[n],lmax=0; for(inti=0;iA[i-1]){ ldp[i]=ldp[i-1
ljlstart
·
2015-09-22 22:00
lintcode
-空格替换-212
设计一种方法,将一个字符串中的所有空格替换成%20。你可以假设该字符串有足够的空间来加入新的字符,且你得到的是“真实的”字符长度。样例对于字符串"MrJohnSmith",长度为13替换空格之后的结果为"Mr%20John%20Smith"注意如果使用Java或Python,程序中请用字符数组表示字符串。挑战在原字符串(字符数组)中完成替换,不适用额外空间 classSolution{ pub
ljlstart
·
2015-09-22 21:00
LintCode
-- 不同的路径
LintCode
-- unique-paths(不同的路径)原题链接:http://www.
lintcode
.com/zh-cn/problem/unique-paths/有一个机器人的位于一个M×N个网格左上角
chan15
·
2015-09-22 17:00
算法
lintcode
LintCode
--最长上升连续子序列
lintcode
--longest-increasing-continuous-subsequence(最长上升连续子序列)原题链接:http://www.
lintcode
.com/zh-cn/problem
chan15
·
2015-09-22 16:00
算法
lintcode
LintCode
--最大子数组差
LintCode
--maximum-subarray-difference(最大子数组差)原题链接:http://www.
lintcode
.com/zh-cn/problem/maximum-subarray-difference
chan15
·
2015-09-21 22:00
算法
lintcode
lintcode
-二叉查找树中搜索区间-11
给定两个值k1和k2(k1val=val; *this->left=this->right=NULL; *} *} */ classSolution{ public: voidmiddle_order(TreeNode*root,vector&base,intk1,intk2){ if(!root) return; middle_order(root->left,base,k1,k2); if(
ljlstart
·
2015-09-21 21:00
LintCode
--最小子数组
LintCode
--minimum-subarray(最小子数组)原题链接:http://www.
lintcode
.com/zh-cn/problem/minimum-subarray/给定一个整数数组
funggor
·
2015-09-21 21:46
LintCode
LintCode
--最小子数组
LintCode
--minimum-subarray(最小子数组)原题链接:http://www.
lintcode
.com/zh-cn/problem/minimum-subarray/给定一个整数数组
chan15
·
2015-09-21 21:00
算法
lintcode
lintcode
-合并两个排序链表 -165
/** *DefinitionofListNode *classListNode{ *public: *intval; *ListNode*next; *ListNode(intval){ *this->val=val; *this->next=NULL; *} *} */ classSolution{ public: ListNode*mergeTwoLists(ListNode*l1,Lis
ljlstart
·
2015-09-21 20:00
LintCode
--数飞机
LintCode
--number-of-airplanes-in-the-sky(数飞机)原题链接:http://www.
lintcode
.com/zh-cn/problem/number-of-airplanes-in-the-sky
chan15
·
2015-09-21 20:00
算法
lintcode
LintCode
--翻转二叉树(非递归)
LintCode
--invert-binary-tree(翻转二叉树-非递归)原题链接:http://www.
lintcode
.com/zh-cn/problem/invert-binary-tree/
chan15
·
2015-09-21 20:00
算法
二叉树
lintcode
LintCode
-- 寻找缺失的数
LintCode
--find-the-missing-number(寻找缺失的数)原题链接:http://www.
lintcode
.com/zh-cn/problem/find-the-missing-number
chan15
·
2015-09-21 20:00
算法
lintcode
LintCode
--买卖股票的最佳时机
LintCode
--best-time-to-buy-and-sell-stock(买卖股票的最佳时机)原题链接:http://www.
lintcode
.com/zh-cn/problem/best-time-to-buy-and-sell-stock
chan15
·
2015-09-21 20:00
算法
lintcode
LintCode
--买卖股票的最佳时机 II
LintCode
--best-time-to-buy-and-sell-stock-ii(买卖股票的最佳时机II)原题链接:http://www.
lintcode
.com/zh-cn/problem/best-time-to-buy-and-sell-stock-ii
chan15
·
2015-09-21 20:00
算法
lintcode
lintcode
-删除排序数组中的重复数字II-101
跟进“删除重复数字”:如果可以允许出现两次重复将如何处理?样例给出数组A=[1,1,1,2,2,3],你的函数应该返回长度5,此时A=[1,1,2,2,3]。classSolution{ public: intremoveDuplicates(vector&nums){ if(nums.empty()) return0; mapcheck; intfast=0,slow=0; while(fa
ljlstart
·
2015-09-21 00:00
lintcode
-跳跃游戏II-117
给出一个非负整数数组,你最初定位在数组的第一个位置。数组中的每个元素代表你在那个位置可以跳跃的最大长度。你的目标是使用最少的跳跃次数到达数组的最后一个位置。样例给出数组A=[2,3,1,1,4],最少到达数组最后一个位置的跳跃次数是2(从数组下标0跳一步到数组下标1,然后跳3步到数组的最后一个位置,一共跳跃2次)classSolution{ public: intjump(vectorA){ i
ljlstart
·
2015-09-20 22:00
lintcode
-矩阵归零-162
给定一个m×n矩阵,如果一个元素是0,则将其所在行和列全部元素变成0。需要在原地完成。样例给出一个矩阵[[1,2],[0,3]],返回[[0,2],[0,0]]挑战你是否使用了额外的空间?一个直接的解决方案是使用O(MN)的额外空间,但这并不是一个好的方案。一个简单的改进方案是使用O(M+N)的额外空间,但这仍然不是最好的解决方案。你能想出一个常数空间的解决方案吗?O(M*N)classSolut
ljlstart
·
2015-09-20 21:00
lintcode
-在二叉查找树中插入节点-85
给定一棵二叉查找树和一个新的树节点,将节点插入到树中。你需要保证该树仍然是一棵二叉查找树。样例给出如下一棵二叉查找树,在插入节点6之后这棵二叉查找树可以是这样的:22/\/\14-->14//\336挑战能否不使用递归?/** *DefinitionofTreeNode: *classTreeNode{ *public: *intval; *TreeNode*left,*right; *TreeN
ljlstart
·
2015-09-20 00:00
lintcode
- k数和II-90
给定n个不同的正整数,整数k(1,bool>check; vectorbase; voidbacktracing(vector>&ret,vector&arr,intcur,intleft,intk,intn){ if(0==k){ if(0==left){ ret.push_back(base); } return; } for(inti=cur;i>kSumII(vectorA,intk,in
ljlstart
·
2015-09-20 00:00
lintcode
-跳跃游戏-116
给出一个非负整数数组,你最初定位在数组的第一个位置。数组中的每个元素代表你在那个位置可以跳跃的最大长度。判断你是否能到达数组的最后一个位置。样例A=[2,3,1,1,4],返回true.A=[3,2,1,0,4],返回false.classSolution{ public: boolcanJump(vector&A){ intmaxN=0;//记录能走的最大步数 inti=0;//记录当前走到
ljlstart
·
2015-09-19 23:00
lintcode
-旋转图像-161
给定一个N×N的二维矩阵表示图像,90度顺时针旋转图像。样例给出一个矩形[[1,2],[3,4]],90度顺时针旋转后,返回[[3,1],[4,2]]挑战能否在原地完成?常规解法:classSolution{ public: voidrotate(vector>&matrix){ if(matrix.empty()) return; constintrow=matrix[0].size();
ljlstart
·
2015-09-19 23:00
lintcode
-堆化-130
给出一个整数数组,堆化操作就是把它变成一个最小堆数组。对于堆数组A,A[0]是堆的根,并对于每个A[i],A[i*2+1]是A[i]的左儿子并且A[i*2+2]是A[i]的右儿子。样例给出[3,2,1,4,5],返回[1,2,3,4,5]或者任何一个合法的堆数组挑战O(n)的时间复杂度完成堆化说明什么是堆?堆是一种数据结构,它通常有三种方法:push,pop和top。其中,“push”添加新的元素
ljlstart
·
2015-09-19 23:00
lintcode
-拓扑排序-127
给定一个有向图,图节点的拓扑排序被定义为:对于每条有向边A--> B,则A必须排在B之前拓扑排序的第一个节点可以是任何在图中没有其他节点指向它的节点/** *DefinitionforDirectedgraph. *structDirectedGraphNode{ *intlabel; *vectorneighbors; *DirectedGraphNode(intx):label(x){}; *
ljlstart
·
2015-09-19 20:00
lintcode
-旋转链表-170
给定一个链表,旋转链表,使得每个节点向右移动k个位置,其中k是一个非负数样例给出链表1->2->3->4->5->null和k=2返回4->5->1->2->3->null/** *Definitionforsingly-linkedlist. *structListNode{ *intval; *ListNode*next; *ListNode(intx):val(x),next(NULL){}
ljlstart
·
2015-09-19 20:00
lintcode
-带最小值操作的栈-12
实现一个带有取最小值min方法的栈,min方法将返回当前栈中的最小值。你实现的栈将支持push,pop和min操作,所有操作要求都在O(1)时间内完成。样例如下操作:push(1),pop(),push(2),push(3),min(),push(1),min()返回1,2,1注意如果堆栈中没有数字则不能进行min方法的调用classMinStack{ public: stacksdata; s
ljlstart
·
2015-09-17 09:00
lintcode
-搜索二维矩阵II-38
写出一个高效的算法来搜索m×n矩阵中的值,返回这个值出现的次数。这个矩阵具有以下特性:每行中的整数从左到右是排序的。每一列的整数从上到下是排序的。在每一行或每一列中没有重复的整数。您在真实的面试中是否遇到过这个题?样例考虑下列矩阵:[ [1,3,5,7], [2,4,7,8], [3,5,9,10]]给出target=3,返回2//遵循杨氏矩阵的搜索规律,从左上角开始,target小于矩阵中
ljlstart
·
2015-09-17 09:00
lintcode
-用栈实现队列-40
正如标题所述,你需要使用两个栈来实现队列的一些操作。队列应支持push(element),pop()和top(),其中pop是弹出队列中的第一个(最前面的)元素。pop和top方法都应该返回第一个元素的值。样例比如push(1),pop(),push(2),push(3),top(),pop(),你应该返回1,2和2挑战仅使用两个栈来实现它,不使用任何其他数据结构,push,pop和top的复杂度
ljlstart
·
2015-09-17 09:00
lintcode
-删除排序链表中的重复数字II-113
给定一个排序链表,删除所有重复的元素只留下原链表中没有重复的元素。样例给出1->2->3->3->4->4->5->null,返回1->2->5->null给出1->1->1->2->3->null,返回 2->3->null/** *DefinitionofListNode *classListNode{ *public: *intval; *ListNode*next; *ListNode(i
ljlstart
·
2015-09-17 08:00
lintcode
-最近公共祖先-88
给定一棵二叉树,找到两个节点的最近公共父节点(LCA)。最近公共祖先是两个节点的公共的祖先节点且具有最大深度。样例对于下面这棵二叉树4/\37/\56LCA(3,5)=4LCA(5,6)=7LCA(6,7)=7/** *DefinitionofTreeNode: *classTreeNode{ *public: *intval; *TreeNode*left,*right; *TreeNode(i
ljlstart
·
2015-09-16 23:00
lintcode
-二叉树的层次遍历-69
给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问)您在真实的面试中是否遇到过这个题?样例给出一棵二叉树{3,9,20,#,#,15,7}, 3 /\ 9 20 / \ 15 7返回它的层次遍历为:[ [3], [9,20], [15,7]]挑战只使用一个队列去实现它/** *DefinitionofTreeNode: *classTreeNode{ *public: *intval
ljlstart
·
2015-09-16 21:00
lintcode
-带环链表-102
给定一个链表,判断它是否有环。样例给出-21->10->4->5,tailconnectstonodeindex1,返回true挑战不要使用额外的空间/** *DefinitionofListNode *classListNode{ *public: *intval; *ListNode*next; *ListNode(intval){ *this->val=val; *this->next=NU
ljlstart
·
2015-09-16 17:00
lintcode
-数组剔除元素后的乘积-50
给定一个整数数组A。定义B[i]=A[0]*...*A[i-1]*A[i+1]*...*A[n-1],计算B的时候请不要使用除法。样例给出A=[1,2,3],返回B为[6,3,2]typedeflonglongLong; classSolution{ public: vectorproductExcludeItself(vector&nums){ vectorret; intn; if((n=n
ljlstart
·
2015-09-15 21:00
lintcode
-三数之和-57
给出一个有n个整数的数组S,在S中找到三个整数a,b,c,找到所有使得a+b+c=0的三元组。样例如S= {-1012-1-4},你需要返回的三元组集合的是:(-1,0,1)(-1,-1,2)注意在三元组(a,b,c),要求a,bool>check;//防止相同的序列放入结果中 voidbacktracing(vector>&ret,vector&nums,vector&vec,intcur,in
ljlstart
·
2015-09-15 21:00
lintcode
-落单的数II-83
给出3*n+1个的数字,除其中一个数字之外其他每个数字均出现三次,找到这个数字。样例给出 [1,1,2,3,3,3,2,2,4,1] ,返回4挑战一次遍历,常数级的额外空间复杂度#defineBit32 classSolution{ public: intsingleNumberII(vector&A){ intcount,ret=0; for(inti=0;i
ljlstart
·
2015-09-15 11:00
lintcode
-O(1)检测2的幂次-142
用O(1)时间检测整数 n 是否是 2 的幂次。样例n=4,返回 true;n=5,返回 false.注意O(1)时间复杂度说明:该方法并没有能满足题目要求的时间复杂度,但这是一个常规的解法。classSolution{ public: boolcheckPowerOf2(intn){ intcount=0;//记录n的二进制中有多少个1 if(n<0)//注意负数 returnfalse; w
ljlstart
·
2015-09-15 10:00
lintcode
-两数之和-56
给一个整数数组,找到两个数使得他们的和等于一个给定的数target。你需要实现的函数twoSum需要返回这两个数的下标,并且第一个下标小于第二个下标。注意这里下标的范围是1到n,不是以0开头。样例numbers=[2,7,11,15], target=9return [1,2]classSolution{ public: mapvis; vectortwoSum(vector&nums,int
ljlstart
·
2015-09-15 00:00
lintcode
-最长公共子串-79
给出两个字符串,找到最长公共子串,并返回其长度。样例给出A=“ABCD”,B=“CBCE”,返回2注意子串的字符应该连续的出现在原字符串中,这与子序列有所不同。classSolution{ public: intlongestCommonSubstring(string&A,string&B){ if(A.empty()||B.empty()) return0; intdp[A.length()
ljlstart
·
2015-09-14 22:00
上一页
77
78
79
80
81
82
83
84
下一页
按字母分类:
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
其他