
LeetCode编程
ke1950523491
这个作者很懒,什么都没留下…
展开
-
LeetCode-338. Counting Bits
LeetCode-338. Counting Bits 题目描述:https://leetcode.com/problems/counting-bits/ 解题思路 当然,如果逐位取模再判断是不是1来计算1的个数当然可以,但这样时间复杂度就是O(n*sizeof(integer)) 了,我们想要O(n) 就好。 所以,在于对给定的数num ,我们对区间0 ≤ i ≤ num中的每个数求1 的...原创 2019-12-11 11:26:35 · 191 阅读 · 0 评论 -
LeetCode-537. Complex Number Multiplication
LeetCode-537. Complex Number Multiplication 题目链接:https://leetcode.com/problems/complex-number-multiplication/ 解题思路 复数的乘法本来也不难,加上题目输入和输出的格式都很规范,一定是实数加虚数的格式:A+Bi 哪怕A是0,B是0或者负数,都是这个格式,所以变简单更多了。 代码实现-...原创 2019-12-10 09:36:52 · 127 阅读 · 0 评论 -
LeetCode-1104. Path In Zigzag Labelled Binary Tree
LeetCode-1104. Path In Zigzag Labelled Binary Tree 题目描述:https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree/ 解题思路 二叉树的节点全满的话一般都会有些数学规律的,要善于发现数学规律,二叉树层数用n表示(层数从0层开始数),每一层的节点数为2^n (题目表明...原创 2019-12-03 11:19:34 · 196 阅读 · 0 评论 -
LeetCode-1161. Maximum Level Sum of a Binary Tree
LeetCode-1161. Maximum Level Sum of a Binary Tree 原题链接:https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/ 解题思路 其实就是二叉树的层次遍历的变种而已,二叉树层次遍历应该都很熟悉了,就不多说了 算法描述 Step1:如果根节点root为空,返回0 Ste...原创 2019-11-29 09:00:10 · 194 阅读 · 0 评论 -
LeetCode-894. All Possible Full Binary Trees
LeetCode-894. All Possible Full Binary Trees 题目描述链接:https://leetcode.com/problems/all-possible-full-binary-trees/ 解题思路 一开始看到题目也是没太多想法,分析一个内在的规律相信大家就能融会贯通了: 要是完全二叉树,节点数必须是奇数; 对于一个N个节点的完全二叉树,如果左子树用了...原创 2019-11-28 09:29:00 · 150 阅读 · 0 评论 -
LeetCode 763. Partition Labels
LeetCode 763. Partition Labels 这题挺考究思维的,一开始我也不会,也是看别人的分析自己再重新思考和编码 题目描述 A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter...原创 2019-11-27 09:53:47 · 165 阅读 · 0 评论