首页 > TAG信息列表 > binary

记录 Post man 上传 binary, 用 Python 的 requests 上传

用 Post man 的 Code snipet, 可以选不同编程语言的实现代码      

leetcode 637. Average of Levels in Binary Tree 二叉树的层平均值(简单)

一、题目大意 给定一个非空二叉树的根节点 root , 以数组的形式返回每一层节点的平均值。与实际答案相差 10-5 以内的答案可以被接受。 示例 1: 输入:root = [3,9,20,null,null,15,7] 输出:[3.00000,14.50000,11.00000] 解释:第 0 层的平均值为 3,第 1 层的平均值为 14.5,第 2 层的

leetcode 110. Balanced Binary Tree 平衡二叉树(简单)

一、题目大意 给定一个二叉树,判断它是否是高度平衡的二叉树。 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1 。 示例 1: 输入:root = [3,9,20,null,null,15,7] 输出:true 示例 2: 输入:root = [1,2,2,3,3,null,null,4,4] 输出:false

701.insert-into-a-binary-search-tree 二叉搜索树中的插入操作

没啥好说的,但是要注意连续两个if和if... else if之间的区别。 class Solution { public: TreeNode *insertIntoBST(TreeNode *root, int val) { if (root == nullptr) { TreeNode *res = new TreeNode(val); return res; }

VSCode .wasm viewer extension All In One

VSCode .wasm viewer extension All In One Preview WebAssembly Binary files in 2 clicks. ❓ bug, 点击两次不好使呀! https://github.com/wasmerio/vscode-wasm show WebAssembly ✅ Fast convertion between text and binary view. 文本和二进制视图之间的快速转换。 We

LeetCode 1339. Maximum Product of Splitted Binary Tree

原题链接在这里:https://leetcode.com/problems/maximum-product-of-splitted-binary-tree/ 题目: Given the root of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized. Return t

98.validate-binary-search-tree 验证二叉搜索树

二叉搜索树定义: 节点左子树只包含小于当前节点的数; 节点右子树只包含大于当前节点的数; 所有左子树和右子树自身必须也是二叉搜索树。 实际上,若中序遍历二叉搜索树,所得序列是单调递增的,利用这一性质来判断是否是二叉搜索树。 递归法 创建一个指针pre,指向中序遍历过程中的当前节点

jerry99的序列 --binary search, math

    #include <bits/stdc++.h> using namespace std; using i64 = long long; const int N = 1e5 + 10; const int M = N - 10; int tot, vis[N], prime[N]; //#define LOCAL void sieve () { for (int i = 2; i <= M; ++i) { if (!vis[i])

递归、二分查找

#递归函数: 有最大递归深度,默认接近1000,各版本略有差异 count = 0 def F1(n): n += 1 print(n)#1 2 3……996 F1(n) F1(count) #修改递归深度 import sys sys.setrecursionlimit(100) count = 0 def F2(n): n += 1 print(n) # 1 2 3……96 F2

654.maximum-binary-tree 最大二叉树

递归就好了,没啥好说的。 class Solution { private: int getMax(vector<int> &nums, int l, int r) { int m_index = l; for (int i = l; i < r; i++) { if (nums[i] >= nums[m_index]) m_index = i; }

106.construct-binary-tree-inorder-and-postorder-traversal 从中序与后序遍历序列构造二叉树

大致思路,首先找到后序遍历序列的最后一个数,二叉树的根节点(root)就是这个值,然后在中序遍历序列里找到这个数所在的位置(假设索引为i),i左边的数,是根节点左子树的数值,i右边的数,是根节点的右子树,然后根据左子树和右子树的数量,划分后序遍历的序列,分别找出划分后的两个序列的根节点,然

Review binary search

33. 搜索旋转排序数组 - 力扣(LeetCode) 81. 搜索旋转排序数组 II - 力扣(LeetCode) 153. 寻找旋转排序数组中的最小值 - 力扣(LeetCode) 154. 寻找旋转排序数组中的最小值 II - 力扣(LeetCode) 34. 在排序数组中查找元素的第一个和最后一个位置 - 力扣(LeetCode) 35. 搜索插入位置 - 力扣(Le

110.balanced-binary-tree 平衡二叉树

获取左右子树的高度,如果左右子树高度差小于等于1,则判断左右子树的左右子树,如此递归下去。 class Solution { public: int getDp(TreeNode *root) { if (root == nullptr) return 0; int ldp = getDp(root->left); int rdp = getDp(root

[Oracle] LeetCode 696 Count Binary Substrings

Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively. Substrings that occur multiple times are counte

Time Needed to Rearrange a Binary String

Time Needed to Rearrange a Binary String You are given a binary string $s$. In one second, all occurrences of 01 are simultaneously replaced with 10 . This process repeats until no occurrences of 01 exist. Return the number of seconds needed to complete

[Google] LeetCode 366 Find Leaves of Binary Tree

Given the root of a binary tree, collect a tree's nodes as if you were doing this: Collect all the leaf nodes. Remove all the leaf nodes. Repeat until the tree is empty. Solution 每次需要删去叶子节点。 我们利用 \(dfs\):对于叶子节点的,我们将其深度返回 \(-1\).

[Google] LeetCode 2096 Step-By-Step Directions From a Binary Tree Node to Another

You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer destValue representing the value of the

[Oracle] LeetCode 1740 Find Distance in a Binary Tree

Given the root of a binary tree and two integers p and q, return the distance between the nodes of value p and value q in the tree. The distance between two nodes is the number of edges on the path from one to the other. Solution 求树上两个点之间的距离。很经

145.binary-tree-postorder-traversal 二叉树的后序遍历

对比前序遍历的"中左右",后序遍历是"左右中",颠倒一下就是"中右左",所以可以参照前序遍历的迭代法来写迭代遍历。 #include <algorithm> #include <stack> #include <vector> using std::stack; using std::vector; class Solution { public: vector<int> postord

CF1477B Nezzar and Binary String

题目链接: 洛谷 Codeforces Solution 我一开始以为是道结论题,一直想贪心策略,后来卡了二十多分钟,感觉不行,赶紧换方法。 这题不能正着做,只能反过来,从答案串往原串推,因为正着做有后效性,十分恶心。反过来做以后,顺序就变了,即先改后看,对于每一次检查的区间 \([l,r]\),我们这次修改,一定要改

binary tree+tree order

二叉树的前中序确定后序:http://acm.hdu.edu.cn/showproblem.php?pid=1710 二叉树的后中序确定层序:https://pintia.cn/problem-sets/994805342720868352/problems/994805485033603072 二叉树的前中序确定后序变形:https://pintia.cn/problem-sets/994805342720868352/problems/99480

查找算法binary_search

#include <iostream> #include <vector> #include <algorithm> using namespace std; class Print { public: void operator()(int i) { cout << i << endl; } }; int main() { vector<int> v; for(int i = 0; i

[LeetCode] 1161. Maximum Level Sum of a Binary Tree

Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of nodes at level x is maximal. Example 1: Input: root = [1,7,0,7,-8,null,null]

LeetCode 108 Convert Sorted Array to Binary Search Tree DFS

Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more tha

LeetCode 103 Binary Tree Zigzag Level Order Traversal 双端队列 Deque

Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between). Solution 由于是 \(zigzag\) 的形式,刚开始的思路是用 \(stack\) 来维护反序,但是