自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 资源 (1)
  • 收藏
  • 关注

原创 Find Leaves of Binary Tree - LintCode

描述 给定一个二叉树,像这样收集树节点:收集并移除所有叶子,重复,直到树为空。 样例 Given binary tree: 1 / \ 2 3 / \ 4 5 Returns [[4, 5, 3], [2], [1]]. 思路 #ifndef C650_H #define C650_H #include<iostream&g...

2018-06-30 23:02:38 254

原创 Sum Root to Leaf Numbers - LintCode

描述 Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the ...

2018-06-30 22:55:28 145

原创 字符串构造二叉树 - LintCode

描述 您需要从包含括号和整数的字符串中构造一个二叉树。 整个的输入表示一个二叉树。它包含一个整数,或零,或两对括号。该整数表示根的值,而一对括号包含一个具有相同结构的子二叉树。 如果父节点存在,您总是首先开始构造它的左子节点。 在输入字符串中只有'(',')','-'和'0' ~ '9'。 空树表示为“”而不是“()”。 样例 给定 s = “4(2(3)(1))(6(5))”, ...

2018-06-30 16:55:53 2403

原创 Binary Tree Tilt - LintCode

描述 Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subt...

2018-06-30 16:15:47 183

原创 Subtree of Another Tree - LintCode

描述 Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this ...

2018-06-30 16:05:39 164

原创 Sum of Left Leaves - LintCode

描述 Find the sum of all left leaves in a given binary tree. 样例 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. ...

2018-06-27 11:08:32 140

原创 二叉树最长连续序列 - LintCode

描述 给一棵二叉树,找到最长连续路径的长度。 这条路径是指 任何的节点序列中的起始节点到树中的任一节点都必须遵循 父-子 联系。最长的连续路径必须是从父亲节点到孩子节点(不能逆序)。 样例 举个例子: 1 \ 3 / \ 2 4 \ 5 最长的连续路径为 3-4-5,所以返回 3。 2 \ ...

2018-06-23 21:44:05 1215

原创 Compare Version Numbers - LintCode

描述 Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assume that the version strings are non-em...

2018-06-21 15:49:06 149

原创 Symmetric Tree - LintCode

描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). Bonus points if you could solve it both recursively and iteratively. 样例 For example, this binary t...

2018-06-21 14:21:52 182

原创 尾随零 - LintCode

描述 给定一个整数n,返回n!(n的阶乘)的尾随零的个数。 您的解法时间复杂度应为对数级别。 思路 由于2和5可以形成0,且2的个数总是多于5,所以尾部0的个数是由0~n中包含5的个数决定的。譬如,5包含1个5,10包含1个5,25包含两个5… #ifndef C1347_H #define C1347_H #include<iostream> using namespa...

2018-06-21 13:51:42 758

原创 Repeated DNA Sequences - LintCode

描述 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. W...

2018-06-14 20:30:07 130

原创 抽搐词 - LintCode

描述 我们正常的单词不会有连续两个以上相同的字母,如果出现连续三个或以上的字母,那么这是一个抽搐词。现在给一个单词,从左至右求出所有抽搐字母的起始点和结束点。 输入的字符串长度为n,n <= 100000。 样例 给出 str = “whaaaaatttsup”, 返回 [[2,6],[7,9]]。 解释: "aaaa"和"ttt"是抽搐字母,输出他们的起始点和结束点。 ...

2018-06-12 22:23:06 485

原创 最长AB子串 - LintCode

描述 给你一个只由字母’A’和’B’组成的字符串s,找一个最长的子串,要求这个子串里面’A’和’B’的数目相等,输出该子串的长度。 这个子串可以为空。 s的长度n满足 2<=n<=1000000。 样例 给定s=”ABAAABBBA”,返回8。 解释: 子串 s[0,7] 和子串 s[1,8] 满足条件,长度为 8。 给定s=”AAAAAA”,返回0。 解释: s...

2018-06-11 21:51:00 1784 1

原创 染色问题 - LintCode

描述 有一个圆形,分成n个扇形,用m种颜色给每个扇形染色,相邻扇形颜色不能相同。求方案总数。 不考虑对称性。 由于这个数可能很大,因此只需返回方案数模1e9 + 7。 1≤n≤105,1≤m≤1051≤n≤105,1≤m≤1051≤n≤10^5 ,1≤m≤10^5 ​ 样例 给定n = 2,m = 3,返回6。 解释: 一个圆划分为 2 个扇形,用 3 种颜色上色方案有“黑红...

2018-06-11 20:03:10 3054

原创 覆盖数字 - LintCode

描述 给出一些区间,问覆盖次数最多的数是多少,如果有多个,输出最小的那个数。 区间的个数不大于10^5。 区间的左右端点大于0小于等于10^5。 样例 给出 intervals = [(1,7),(2,8)], 返回 2。 解释: 2被覆盖了2次,且是覆盖2次中最小的数。 给出 intervals = [(1,3),(2,3),(3,4)], 返回 3。 解释: 3被覆盖了3...

2018-06-06 10:49:27 330

原创 Basic Calculator III - LintCode

描述 Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empt...

2018-06-05 21:42:45 391

原创 Basic Calculator - LintCode

描述 Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empt...

2018-06-05 08:21:32 153

原创 树 - LintCode

描述 给出两个list x,y,代表x[i]与y[i]之间有一条边,整个边集构成一棵树,1为根,现在有个list a,b,表示询问节点a[i]与b[i]是什么关系,如果a[i]与b[i]是兄弟,即有同一个父节点,输出1,如果a[i]与b[i]是父子关系,输出2,否则输出0。 节点数不大于100000。 所以的数均为不大于100000的正整数 样例 给出 x = [1,1], y = [...

2018-06-02 21:07:34 155

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除