首页
学习
活动
专区
工具
TVP
发布

算法修养

专栏作者
674
文章
385128
阅读量
49
订阅数
LeetCode weekly contest 278 (amazon pay)
第三题 O(n)的计算hash值。利用取模运算法则,从后往前先计算k个字符的hash 值, 然后开始向左移动,每次移动都要先减去右边最后一个值,然后再乘以P,最后加上左边的
ShenduCC
2022-03-10
2620
LeetCode 226. Invert Binary Tree
题目 翻转二叉树 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: TreeNode* invertTree(T
ShenduCC
2022-03-10
1880
LeetCode 1803. Count Pairs With XOR in a Range (二叉树)
题目 在一个数组里面找到两个数异或的结果在某个范围之内。 这种题目,就要用二叉树, 代码写的又臭又长。。 struct Node { int value; int left; int right; int num; int pos; }tree[200005]; class Solution { public: int hight; int lower; int fun(int root, int number, int h, int l, int pos) { if(pos==
ShenduCC
2021-06-22
3020
LeetCode 222. Count Complete Tree Nodes(二分+位运算)
题解:DFS 或者BFS都太low,我们可以用O(log(n)^2)的效率解决,n为节点个数,log(n)就是树的高度。
ShenduCC
2020-02-25
3520
LeetCode 199. Binary Tree Right Side View
题目 题意:假如你在一棵二叉树的右边,往左看,能看到哪些元素。 题解:广搜,每一层的最右边元素即可。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ struct No
ShenduCC
2020-02-19
2720
LeetCode 98. Validate Binary Search Tree( 递归,BST )
题解:所有思路都是去找二叉树中不满足BST性质的节点,找到了,就不符合,找不到就符合。那么怎么去找呢?我提供两种思想。
ShenduCC
2020-02-14
4630
LeetCode 124 Binary Tree Maximum Path Sum
https://leetcode.com/problems/binary-tree-maximum-path-sum/description/
ShenduCC
2018-07-24
2510
LeetCode 117 Populating Next Right Pointers in Each Node II
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
ShenduCC
2018-07-24
2140
LeetCode 116 Populating Next Right Pointers in Each Node
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
ShenduCC
2018-07-24
1850
LeetCode 114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.
ShenduCC
2018-07-24
3340
LeetCode 107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
ShenduCC
2018-07-24
2560
LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.
ShenduCC
2018-07-24
3190
LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.
ShenduCC
2018-07-24
2520
LeetCode 110 Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Example 1: Given the following tree [
ShenduCC
2018-07-04
2370
LeetCode 102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its level order traversal as: [ [
ShenduCC
2018-06-21
2650
2016天梯模拟赛 进阶题解
L2-005 集合相似度 题目链接: https://www.patest.cn/contests/gplt/L2-005 题目的意思是要求两个集合的交集中互不相同元素的个数和两个集合并集中互不相同的元素的个数 先求交集中互不相同的元素,然后用两个集合互不相同元素个数的和减去,就是并集中的个数 #include <iostream> #include <string.h> #include <stdlib.h> #include <algorithm> #include <math.h> #includ
ShenduCC
2018-04-26
7840
没有更多了
社区活动
腾讯技术创作狂欢月
“码”上创作 21 天,分 10000 元奖品池!
Python精品学习库
代码在线跑,知识轻松学
博客搬家 | 分享价值百万资源包
自行/邀约他人一键搬运博客,速成社区影响力并领取好礼
技术创作特训营·精选知识专栏
往期视频·千货材料·成员作品 最新动态
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档