题目链接:https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal/ 方法一递归法:先访问子节点,然后访问根。LeetCode代码: /* // Definition for a Node. class Node { public ...
分类:
其他好文 时间:
2020-07-16 21:39:10
阅读次数:
79
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { ...
分类:
其他好文 时间:
2020-07-16 00:01:06
阅读次数:
61
# 二叉搜索树的特点是左子树小于根节点,右子树大于根节点。# 因此当根节点为i的时候,左子树的值为1:i-1,右子树为i+1:n# 当节点为n的时候所有的能够组成的树为左子树个数乘以右子树个数。class Solution: def numTrees(self, n: int) -> int: dp ...
分类:
其他好文 时间:
2020-07-15 23:51:44
阅读次数:
62
题目描述链接:https://leetcode-cn.com/problems/search-in-a-binary-search-tree/ 基本思路:等于返回,当前节点值大于搜索值从左子树搜索,小于从右子树搜索。以此可以用递归或迭代法实现,下面分别展示两种方法; (1)采用递归的方法 LeetC ...
分类:
其他好文 时间:
2020-07-15 23:43:11
阅读次数:
76
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ ...
分类:
其他好文 时间:
2020-07-15 23:40:01
阅读次数:
70
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ ...
分类:
其他好文 时间:
2020-07-15 23:31:48
阅读次数:
66
96. 不同的二叉搜索树 题目来源:力扣(LeetCode)https://leetcode-cn.com/problems/unique-binary-search-trees 题目 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 输入: 3 输出: 5 解释: ...
分类:
编程语言 时间:
2020-07-15 23:11:39
阅读次数:
74
96. 不同的二叉搜索树 自己用dp写的哈哈哈不是很整洁 class Solution { public int numTrees(int n) { int[] res = new int[n + 1]; if(n == 1)return 1; if(n == 2)return 2; res[0] ...
分类:
其他好文 时间:
2020-07-15 23:10:11
阅读次数:
58
代码 https://github.com/smallinsect/MyGo/tree/master/myjson MyUsers.json文件内容 { "name": "小昆虫", "age": 2233, "account_id": "2222222aaaaa", "password": "** ...
分类:
Web程序 时间:
2020-07-15 22:56:01
阅读次数:
155
##题目大意 用栈的形式给出一棵二叉树的建立的顺序,求这棵二叉树的后序遍历 ##tips string用printf输出:printf(“%s”, str.c_str()); ##AC代码 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #inc ...
分类:
其他好文 时间:
2020-07-15 22:48:44
阅读次数:
44