码迷,mamicode.com
首页 >  
搜索关键字:lintcode    ( 1584个结果
[LintCode] Count of Smaller Number before itself
Count of Smaller Number before itselfGive you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) . For e...
分类:其他好文   时间:2015-06-14 21:24:33    阅读次数:538
Lintcode前序遍历和中序遍历树构造二叉树
样例 给出中序遍历:[1,2,3]和前序遍历:[2,1,3]. 返回如下的树: 2 / 1 /** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * ...
分类:其他好文   时间:2015-06-14 16:41:30    阅读次数:123
九章算法面试题75 二叉树的最小深度
九章算法官网-原文网址 http://www.jiuzhang.com/problem/76/ 题目 给定一个二叉树,找出其最小深度。 二叉树的最小深度为根节点到最近叶子节点的距离。 在线测试本题 http://www.lintcode.com/zh-cn/problem/minimum-depth-of-binary-tree/ 解答 方法一:递归...
分类:编程语言   时间:2015-06-14 12:37:04    阅读次数:125
九章算法面试题73 翻转链表II
九章算法官网-原文网址 http://www.jiuzhang.com/problem/74/ 题目 给一个链表,然后我们要把这个链表中第m个节点到第n个节点的部分翻转。 在线测试本题 http://www.lintcode.com/en/problem/reverse-linked-list-ii/ 解答 为更好处理表头和第m个节点,引入dummy结点,...
分类:编程语言   时间:2015-06-14 12:36:24    阅读次数:153
九章算法面试题76 搜索二维矩阵
九章算法官网-原文网址 http://www.jiuzhang.com/problem/77/ 题目 写出一个高效的算法来搜索 m × n矩阵中的值。 这个矩阵具有以下特性: 1) 每行中的整数从左到右是排序的。 2) 每行的第一个数大于上一行的最后一个整数。 在线测试本题 http://www.lintcode.com/zh-cn/problem/search...
分类:编程语言   时间:2015-06-14 12:33:13    阅读次数:145
Climbing Stairs爬楼梯——动态规划
题目描述: 初阶:有n层的台阶,一开始你站在第0层,每次可以爬两层或者一层。请问爬到第n层有多少种不同的方法? 进阶:如果每次可以爬两层,和倒退一层,同一个位置不能重复走,请问爬到第n层有多少种不同的方法? 解题思路: 初阶:一维动态规划。爬楼梯数目其实是一个斐波拉契数列。 假定f[i] 表示是爬到第i层的方法,那么f[i] = f[i-1] + f[i-2] //第i层的方...
分类:其他好文   时间:2015-06-12 11:53:07    阅读次数:116
[LintCode] Max Tree
Max TreeGiven an integer array with no duplicates. A max tree building on this array is defined as follow:The root is the maximum number in the arrayT...
分类:其他好文   时间:2015-06-11 18:58:01    阅读次数:228
求平方根——分治法
题目描述: 不用sqrt(x)库函数,实现求平方根。 解题思路: 采用二分法 假定要求数num的平方根,那么首先取1~num之间的中点mid。 若 mid * mid > num,那么 根在 1~mid-1之间; 若 mid * mid 若 mid * mid == num,直接输出 mid; 由于整数int求平方根是向下取整,所以,若mid * mid if (mi...
分类:其他好文   时间:2015-06-11 11:10:26    阅读次数:100
[LintCode] Maximum Subarray III
Maximum Subarray IIIGiven an array of integers and a numberk, find knon-overlappingsubarrays which have the largest sum.The number in each subarray sh...
分类:其他好文   时间:2015-06-10 19:19:20    阅读次数:170
Lintcode空格替换
替换字符串里的空格 设计一种方法,将一个字符串中的所有空格替换成 %20 。你可以假设该字符串有足够的空间来加入新的字符,且你得到的是“真实的”字符长度。 class Solution { public: /** * @param string: An array of Char * @param length: The true length of the s...
分类:其他好文   时间:2015-06-08 09:49:57    阅读次数:568
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!