[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 递归和非递归,此提比较简单.广度优先遍历即可.关键之处就在于如何保持访问深度. 下面是4种代码: im…
[LeetCode]199. Binary Tree Right Side View 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/binary-tree-right-side-view/description/ 题目描述: Given a binary tree, imagine yourself standing on the right side of it, return the values of the no…
Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example:Given the following binary tree, 1 <--- / \ 2 3 <--- \ \ 5 4 <-…
Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example: Input: [1,2,3,null,5,null,4] Output: [1, 3, 4] Explanation: 1 <--- / \…
[CF438E]The Child and Binary Tree(多项式运算,生成函数) 题面 有一个大小为\(n\)的集合\(S\) 问所有点权都在集合中,并且点权之和分别为\([0,m]\)的二叉树的个数. \(n,m<=10^5\) 题解 设\(f(i)\)表示点权和为\(i\)的二叉树个数,\(c(i)\)是集合中数的生成函数,那么我们可以得到 \[f(n)=\sum_{i=1}^{n}c(i)\sum_{j=0}^{n-i}f(j)f(n-i-j)\] 显然有\(f(0)=1\) 构…
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combination. Note: All numbers (including target) will be posi…
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution. A sudoku puzzle... ...and its solution numbers marked in red. 题意分析: 本题是要解…
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 →…
[题目] Given a binary tree, return the preordertraversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,2,3] [思路] 有参考,好机智,使用堆栈压入右子树,暂时存储. 左子树遍历完成后遍历右子树. [代码] /** * Definition for a binary tree node. * public class TreeNode { *…
// 我的代码 package Leetcode; /** * 199. Binary Tree Right Side View * address: https://leetcode.com/problems/binary-tree-right-side-view/ * Given a binary tree, imagine yourself standing on the right side of it, * return the values of the nodes you can…