![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
lintcode
xiaocong1990
这个作者很懒,什么都没留下…
展开
-
[lintcode]29. 交叉字符串
链接:http://www.lintcode.com/zh-cn/problem/interleaving-string/ 给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。 您在真实的面试中是否遇到过这个题? Yes 样例 比如 s1 = "aabcc" s2 = "dbbca" - 当 s3 = "aadbbcbcac",返回 tru...原创 2018-03-19 16:40:31 · 300 阅读 · 0 评论 -
[lintcode]421. 简化路径
链接:http://www.lintcode.com/zh-cn/problem/simplify-path/ 给定一个文档(Unix-style)的完全路径,请进行路径简化。 您在真实的面试中是否遇到过这个题? Yes 样例 "/home/", => "/home" "/a/./b/../../c/", => "/c" 思路原创 2018-04-18 11:16:13 · 285 阅读 · 0 评论 -
[lintcode]904. Plus One Linked List
链接:http://www.lintcode.com/zh-cn/problem/plus-one-linked-list/ Given a non-negative integer represented as non-empty a singly linked list of digits, plus one to the integer. You may assume原创 2018-04-12 19:06:56 · 221 阅读 · 0 评论 -
[lintcode]141. x的平方根
链接:https://www.lintcode.com/zh-cn/problem/sqrtx/ 实现int sqrt(int x)函数,计算并返回x的平方根。 您在真实的面试中是否遇到过这个题? Yes 样例 sqrt(3) = 1 sqrt(4) = 2 sqrt(5) = 2 sqrt(10) = 3 cla原创 2018-04-23 13:48:34 · 205 阅读 · 1 评论 -
[lintcode]779. Generalized Abbreviation
链接:http://www.lintcode.com/zh-cn/problem/generalized-abbreviation/ Write a function to generate the generalized abbreviations of a word. 您在真实的面试中是否遇到过这个题? Yes 样例 Give原创 2018-04-19 17:03:34 · 229 阅读 · 0 评论 -
[lintcode]862. Next Closest Time
链接:http://www.lintcode.com/zh-cn/problem/next-closest-time/# Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how m原创 2018-04-20 10:48:36 · 222 阅读 · 0 评论 -
[lintcode]876. 连接字符串
链接:http://lintcode.com/zh-cn/problem/split-concatenated-strings/ 给定一个字符串列表,您可以将这些字符串连接到一个循环中,在这个循环中,您可以选择将其反转。在所有可能的循环中,您需要在删除循环之后找到字母顺序最大的字符串,这将使循环字符串成为一个普通的字符串。 具体来说,要找到字母顺序上最大的字符串,您需要经历两个阶段原创 2018-04-21 15:52:49 · 487 阅读 · 0 评论 -
[lintcode]879. 输出赛程表
链接:http://lintcode.com/zh-cn/problem/output-contest-matches/ 在NBA季后赛期间,我们总是安排一支实力相当强的球队去和实力较弱的球队比赛,比如让排名第一的球队和第n队一起比赛,这是一个让比赛更有趣的好策略。现在,你得到了n个团队,你需要以字符串的形式输出他们的最终比赛。 n组以正整数的形式给出,从1到n,表示它们的初始排名原创 2018-04-21 16:10:29 · 254 阅读 · 0 评论 -
[lintcode]248. 统计比给定整数小的数的个数
链接:https://www.lintcode.com/zh-cn/problem/count-of-smaller-number/ 给定一个整数数组 (下标由 0 到 n-1,其中 n 表示数组的规模,数值范围由 0 到 10000),以及一个 查询列表。对于每一个查询,将会给你一个整数,请你返回该数组中小于给定整数的元素的数量。 注意事项 在做此题前,最好先完成原创 2018-05-03 21:03:23 · 314 阅读 · 0 评论 -
[lintcode]414. 两个整数相除
链接:https://www.lintcode.com/zh-cn/problem/divide-two-integers/ 将两个整数相除,要求不使用乘法、除法和 mod 运算符。 如果溢出,返回 2147483647 。 您在真实的面试中是否遇到过这个题? Yes 样例 给定被除数 = 100 ,除数 = 9,返回 11。原创 2018-05-03 21:20:48 · 276 阅读 · 0 评论 -
[lintcode]428. x的n次幂
链接:https://www.lintcode.com/zh-cn/problem/powx-n/ 实现 pow(x,n) 注意事项 不用担心精度,当答案和标准输出差绝对值小于1e-3时都算正确 您在真实的面试中是否遇到过这个题? Yes 样例 Pow(2.1, 3) = 9.261 Pow(0, 1)原创 2018-05-04 16:07:44 · 353 阅读 · 0 评论 -
[lintcode]74. 第一个错误的代码版本
链接:https://www.lintcode.com/zh-cn/problem/first-bad-version/ 代码库的版本号是从 1 到 n 的整数。某一天,有人提交了错误版本的代码,因此造成自身及之后版本的代码在单元测试中均出错。请找出第一个错误的版本号。 你可以通过 isBadVersion 的接口来判断版本号 version 是否在单元测试中出错,具体原创 2018-04-26 19:53:34 · 277 阅读 · 0 评论 -
[lintcode]824. 落单的数 IV
链接:https://www.lintcode.com/problem/single-number-iv/description 描述 给定数组,除了一个数出现一次外,所有数都出现两次,并且所有出现两次的数都挨着。请找出找出那个出现一次的数。 1 为了约束程序的时间复杂度,你的程序将会运行 10^5 次 您在真实的面试中是否遇到过这个题?原创 2018-05-05 17:33:50 · 267 阅读 · 0 评论 -
[lintcode]201. 线段树的构造
链接:https://www.lintcode.com/zh-cn/problem/segment-tree-build/ 线段树是一棵二叉树,他的每个节点包含了两个额外的属性start和end用于表示该节点所代表的区间。start和end都是整数,并按照如下的方式赋值: 根节点的 start 和 end 由 build 方法所给出。对于节点 A 的左儿子,有 start=A.原创 2018-04-27 20:22:32 · 178 阅读 · 0 评论 -
[lintcode]202. 线段树的查询
链接:https://www.lintcode.com/zh-cn/problem/segment-tree-query/ 对于一个有n个数的整数数组,在对应的线段树中, 根节点所代表的区间为0-n-1, 每个节点有一个额外的属性max,值为该节点所代表的数组区间start到end内的最大值。 为SegmentTree设计一个 query 的方法,接受3个参数root, s原创 2018-04-27 20:23:34 · 198 阅读 · 0 评论 -
[lintcode]203. 线段树的修改
链接:https://www.lintcode.com/zh-cn/problem/segment-tree-modify/# 对于一棵 最大线段树, 每个节点包含一个额外的 max 属性,用于存储该节点所代表区间的最大值。 设计一个 modify 的方法,接受三个参数 root、 index 和 value。该方法将 root 为根的线段树中 [start, end]原创 2018-04-28 17:42:45 · 163 阅读 · 0 评论 -
[lintcode]205. 区间最小数
链接:https://www.lintcode.com/zh-cn/problem/interval-minimum-number/ 给定一个整数数组(下标由 0 到 n-1,其中 n 表示数组的规模),以及一个查询列表。每一个查询列表有两个整数 [start, end]。 对于每个查询,计算出数组中从下标 start 到 end 之间的数的最小值,并返回在结果列表中。原创 2018-04-28 19:52:35 · 266 阅读 · 0 评论 -
[lintcode]206. 区间求和 I
链接:https://www.lintcode.com/zh-cn/problem/interval-sum/ 给定一个整数数组(下标由 0 到 n-1,其中 n 表示数组的规模),以及一个查询列表。每一个查询列表有两个整数 [start, end] 。 对于每个查询,计算出数组中从下标 start 到 end 之间的数的总和,并返回在结果列表中。 注意事项 在原创 2018-04-28 20:17:01 · 297 阅读 · 0 评论 -
[lintcode]378. 将二叉查找树转换成双链表
题目链接:http://www.lintcode.com/zh-cn/problem/convert-binary-search-tree-to-doubly-linked-list/ 将一个二叉查找树按照中序遍历转换成双向链表。 您在真实的面试中是否遇到过这个题? Yes 样例 给定一个二叉查找树: 4 / \ 2原创 2018-04-12 14:56:50 · 422 阅读 · 0 评论 -
[lintcode]91. 最小调整代价
链接:http://www.lintcode.com/zh-cn/problem/minimum-adjustment-cost/ Given an integer array, adjust each integers so that the difference of every adjacent integers are not greater than a given number...原创 2018-03-19 16:42:22 · 474 阅读 · 0 评论 -
[lintcode]108. 分割回文串 II
链接:http://www.lintcode.com/zh-cn/problem/palindrome-partitioning-ii/ 给定一个字符串s,将s分割成一些子串,使每个子串都是回文。 返回s符合要求的的最少分割次数。 您在真实的面试中是否遇到过这个题? Yes 样例 比如,给出字符串s = "aab", 返回 1, 因为进行一次分割可以将字符串s分割成["a...原创 2018-03-20 12:52:36 · 256 阅读 · 0 评论 -
[lintcode]118. 不同的子序列
链接:http://www.lintcode.com/zh-cn/problem/distinct-subsequences/给出字符串S和字符串T,计算S的不同的子序列中T出现的个数。子序列字符串是原始字符串通过删除一些(或零个)产生的一个新的字符串,并且对剩下的字符的相对位置没有影响。(比如,“ACE”是“ABCDE”的子序列字符串,而“AEC”不是)。您在真实的面试中是否遇到过这个题?Y...原创 2018-03-20 14:54:37 · 825 阅读 · 1 评论 -
[lintcode]740. 零钱兑换II
链接:http://www.lintcode.com/zh-cn/problem/coin-change-ii/# 给出不同面值的硬币以及总金额. 试写一函数来计算构成该总额的组合数量. 你可以假设每一种硬币你都有无限个. class Solution { public: /** * @param amount: a total amount of money原创 2018-03-24 15:01:31 · 807 阅读 · 0 评论 -
[lintcode]741. Calculate Maximum Value II
链接:http://www.lintcode.com/zh-cn/problem/calculate-maximum-value-ii/ Given a string of numbers, write a function to find the maximum value from the string, you can add a + or * sign between any t原创 2018-03-24 15:28:48 · 194 阅读 · 0 评论 -
[lintcode]752. 流浪剑客斯温
链接:http://www.lintcode.com/zh-cn/problem/rogue-knight-sven/ 在物质位面“现实”中,有n+1个星球,分别为星球0,星球1,……,星球n。 每一个星球都有一个传送门,通过传送门可以直接到达目标星球而不经过其他的星球。 不过传送门有两个缺点。 第一,从星球i通过传送门只能到达编号比i大,且与i的差不超过limit的星球。原创 2018-03-24 16:02:27 · 423 阅读 · 0 评论 -
[lintcode]843. 数字翻转
链接:http://www.lintcode.com/zh-cn/problem/digital-flip/ 给你一个01构成的数组。请你找出最小翻转步数,使得数组满足以下规则: 1的后面可以是1或者0,但是0的后面必须是0。 注意事项 输入的数组长度n 。 您在真实的面试中是否遇到过这个题? Yes 样例原创 2018-03-24 16:41:29 · 704 阅读 · 0 评论 -
[lintcode]867. 4 Keys Keyboard
链接:http://www.lintcode.com/zh-cn/problem/4-keys-keyboard/ Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Key 2: (Ctrl-A): Select the who原创 2018-03-24 17:18:11 · 306 阅读 · 0 评论 -
[lintcode]889. Sentence Screen Fitting
链接:http://www.lintcode.com/zh-cn/problem/sentence-screen-fitting/ Given a rows x cols screen and a sentence represented by a list of non-empty words, find how many times the given sentence can ...原创 2018-03-24 18:55:00 · 350 阅读 · 0 评论 -
[lintcode]909. Android Unlock Patterns
链接:http://www.lintcode.com/zh-cn/problem/android-unlock-patterns/ Given an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total number of unlock pa原创 2018-03-24 20:33:30 · 421 阅读 · 0 评论 -
[lintcode]二叉树最大深度和最小深度
二叉树最大深度 如果二叉树为空,则深度为0 如果不为空,分别求左子树的深度和右子树的深度,去最大的再加1,因为根节点深度是1,要加进去。 class Solution { public: /** * @param root: The root of binary tree. * @return: An integer */原创 2018-03-25 18:38:05 · 214 阅读 · 0 评论 -
[lintcode]98. 链表排序
链接:http://www.lintcode.com/zh-cn/problem/sort-list/ 在 O(n log n) 时间复杂度和常数级的空间复杂度下给链表排序。 您在真实的面试中是否遇到过这个题? Yes 样例 给出 1->3->2->null,给它排序变成 1->2->3->null. 思路:对链原创 2018-04-08 19:01:37 · 295 阅读 · 0 评论 -
[lintcode]88. 最近公共祖先
链接:http://www.lintcode.com/zh-cn/problem/lowest-common-ancestor/ 给定一棵二叉树,找到两个节点的最近公共父节点(LCA)。 最近公共祖先是两个节点的公共的祖先节点且具有最大深度。 注意事项 假设给出的两个节点都在树中存在 您在真实的面试中是否遇到过这个题? Yes原创 2018-03-26 14:11:18 · 297 阅读 · 0 评论 -
[lintcode]717. Tree Longest Path With Same Value
链接:http://www.lintcode.com/zh-cn/problem/tree-longest-path-with-same-value/ 假设有一棵有 N 个节点的无向树, 编号为 1 到 N, 每一个节点都有一个int类型的值,不同的节点可以有相同的值。给一个长度为N的数组A,A[j]表示第j + 1个节点的值。再给一个长度为 (N - 1) * 2 的数组原创 2018-03-26 15:27:32 · 539 阅读 · 0 评论 -
[lintcode]878. Boundary of Binary Tree
链接:http://www.lintcode.com/zh-cn/problem/boundary-of-binary-tree/ Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary includes left b原创 2018-03-26 16:00:19 · 331 阅读 · 0 评论 -
[lintcode]880. Construct Binary Tree from String
链接:http://www.lintcode.com/zh-cn/problem/construct-binary-tree-from-string/ You need to construct a binary tree from a string consisting of parenthesis and integers. The whole input represents原创 2018-03-26 16:27:34 · 310 阅读 · 0 评论 -
[lintcode]36. 翻转链表 II
链接:http://www.lintcode.com/zh-cn/problem/reverse-linked-list-ii/ 翻转链表中第m个节点到第n个节点的部分 注意事项 m,n满足1 ≤ m ≤ n ≤ 链表长度 您在真实的面试中是否遇到过这个题? Yes 样例 给出链表1->2->3->4->原创 2018-04-02 12:27:30 · 250 阅读 · 0 评论 -
[lintcode]136. 分割回文串
链接:https://lintcode.com/problem/palindrome-partitioning/description 描述 给定一个字符串s,将s分割成一些子串,使每个子串都是回文串。 返回s所有可能的回文串分割方案。 您在真实的面试中是否遇到过这个题? 是 样例 给出 s = "aab",返回 [ ["aa", "b"], ["a", "a", ...原创 2018-09-03 12:58:00 · 176 阅读 · 0 评论