ZeoYa's Home


  • Home

  • About

  • Tags

  • Categories

  • Archives

'lintcode 具有最大平均数的子树'

Posted on 2019-04-12 | In algorithm
描述给一棵二叉树,找到有最大平均值的子树。返回子树的根结点 样例样例 1 输入: 1 / \ -5 11 / \ / \1 2 4 -2输出:11(它是一个TreeNode)样例 2 输入: 1 / \ -5 11输出:11(它是一个TreeNode) 思考使用一个函数来遍历这个二叉树。根据后根遍历的顺序遍历每个节点,用左右子树的和来 ...
Read more »

'lintcode 具有K个不同字符的子串'

Posted on 2019-04-12 | In algorithm
描述给定字符串S和整数K.计算长度为K且包含K个不同字符的子串数 样例String: “abcabc”K: 3 Answer: 3substrings: [“abc”, “bca”, “cab”]String: “abacab”K: 3 Answer: 2substrings: [“bac”, “cab”] 思考维护一个数组temp和一个值cnt,记录当前迭代值i之前k个长度的子串中包含的每个不 ...
Read more »

'lintcode K个最近的点'

Posted on 2019-04-12 | In algorithm
描述给定一些 points 和一个 origin,从 points 中找到 k 个离 origin 最近的点。按照距离由小到大返回。如果两个点有相同距离,则按照x值来排序;若x值也相同,就再按照y值排序。 样例例1: 输入: points = [[4,6],[4,7],[4,4],[2,5],[1,1]], origin = [0, 0], k = 3输出: [[1,1],[2,5],[4,4]] ...
Read more »

'lintcode 反向索引'

Posted on 2019-04-12 | In algorithm
描述创建给定文档的反向索引 确保数据不包含标点符号. 样例出一个包括id与内容的文档list(我们提供了document类).返回一个反向索引(hashmap的key是单词, value是文档的id). 例 1: 输入:[ { “id”: 1, “content”: “This is the content of document 1 it is very short” }, { ...
Read more »

'lintcode 删除排序数组中的重复数字'

Posted on 2019-04-12 | In algorithm
lintcode 删除排序数组中的重复数字描述给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度。 不要使用额外的数组空间,必须在原地没有额外空间的条件下完成。 样例给出数组A =[1,1,2],你的函数应该返回长度2,此时A=[1,2]。 思路先说我的思路,删除重复的元素即可,使用vector的迭代器iterator123456789101112131 ...
Read more »

'lintcode 同和分割数组'

Posted on 2019-04-12 | In algorithm
lintcode 同和分割数组描述给定一个有n个整数的数组,需要找到满足以下条件的三胞胎(i, j, k):0 < i, i + 1 < j, j + 1 < k < n - 1每个子数组的和(0,i - 1), (i + 1, j - 1), (j + 1, k - 1)和(k + 1, n - 1)应该相等。我们定义子数组(L, R)表示原始数组从元素索引L到元素索引R ...
Read more »

'lintcode 在排序数组中找最接近的K个数'

Posted on 2019-04-12
描述给一个目标数 target, 一个非负整数 k, 一个按照升序排列的数组 A。在A中找与target最接近的k个整数。返回这k个数并按照与target的接近程度从小到大排序,如果接近程度相当,那么小的数排在前面。 k是一个非负整数,并且总是小于已排序数组的长度。给定数组的长度是正整数, 不会超过 10^4数组中元素的绝对值不会超过 10^4 样例样例 1: 输入: A = [1, 2, 3], ...
Read more »

'lintcode 反转ASCII编码字符串'

Posted on 2019-04-12 | In algorithm
描述给定一个由ascii编码的字符串(例如,“ABC”可以编码为“656667”),您需要编写一个将编码字符串作为输入并返回反转的解码字符串的函数。 您可以假设答案字符串中只有大写字母。 样例样例1 输入: “7976766972”输出: “HELLO”样例2 输入: “656667”输出: “CBA” 思考不断对输入的字符串截取长度为2的字符串,,转为int,再转为char,从后往前构造新的字符 ...
Read more »

'lintcode 合并排序列表'

Posted on 2019-04-12 | In algorithm
描述将两个排序链表合并为一个新的排序链表 样例样例样例 1: 输入: list1 = null, list2 = 0->3->3->null 输出: 0->3->3->null 样例2: 输入: list1 = 1->3->8->11->15->null, list2 = 2->null 输出: 1 ...
Read more »

'lintcode 四数乘积问题'

Posted on 2019-04-12 | In algorithm
描述给定一个长度为n的数组a和一个正整数k,从数组中选择四个数,要求四个数的乘积小于等于k,求方案总数。数组中可能出现多个值相同的数。每次选择四个数时,同一个数不能被选择两次,而值相同的两个不同的数可以同时被选。1 \leq n \leq 10^31≤n≤10​3​​1 \leq a[i] \leq 10^6 (1 \leq i \leq n)1≤a[i]≤10​6​​ (1≤i≤n)1 \leq ...
Read more »
1234…8
ZeoYa

ZeoYa

71 posts
2 categories
11 tags
© 2019 ZeoYa
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4