思路:前序遍历,也就是“根,左,右”的顺序去遍历,递归思路简单,不细说了,把res,结果集合设置成全局变量就行 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; ...
分类:
其他好文 时间:
2020-05-04 15:15:58
阅读次数:
53
前序遍历思路 中序遍历思路 后序遍历思路 法1: 法2: ...
分类:
其他好文 时间:
2020-05-04 13:44:36
阅读次数:
171
题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int ...
分类:
其他好文 时间:
2020-05-03 16:21:26
阅读次数:
53
题目: 解法: 方法一:递归 1 /* 2 // Definition for a Node. 3 class Node { 4 public: 5 int val; 6 vector<Node*> children; 7 8 Node() {} 9 10 Node(int _val) { 11 v ...
分类:
其他好文 时间:
2020-05-03 14:52:04
阅读次数:
50
[TOC] 题目 输入一个序列,最新输入的数字为最低位,如果当前序列能被3整除,输出1,否则输出0。 例如:输入1010_1111,对应1,2,5,10,21,43,87,175,因此输出为:0000_1010. 编程思路 Last_remainder | In | Remainder | Out ...
分类:
其他好文 时间:
2020-05-03 12:33:40
阅读次数:
77
/* program to construct tree using inorder and preorder traversals */ #include <stdio.h> #include <stdlib.h> /* A binary tree node has data, pointer t ...
分类:
其他好文 时间:
2020-05-03 10:19:45
阅读次数:
64
题目描述 根据二叉树的前序遍历和中序遍历的结构,重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不包含重复的数字 解题思路 前序遍历的第一个值为根节点的值,使用这个值将中序遍历结果分成两部分,左部分分为树的左子树中序遍历结果,右部分为树的右子树中序遍历结果。 代码 ...
分类:
其他好文 时间:
2020-05-03 00:39:03
阅读次数:
53
给定一个二叉树,返回它的 前序 遍历。 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,2,3] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 来源:力扣(LeetCode) 解法一:迭代 解法二:递归 /** * Definition for a binary t ...
分类:
其他好文 时间:
2020-05-02 11:38:36
阅读次数:
52
验证前序遍历序列二叉搜索树。题意是给一个二叉搜索树的前序遍历的结果,请你验证这个结果是否正确。例子, Consider the following binary search tree: 5 / \ 2 6 / \ 1 3 Example 1: Input: [5,2,6,1,3] Output: ...
分类:
其他好文 时间:
2020-05-02 09:53:55
阅读次数:
58
1. 递归实现 先序 中序 后序 2. 非递归 前序 中序 后序 ...
分类:
其他好文 时间:
2020-05-01 11:01:06
阅读次数:
50