//超时 /*#include<stdio.h> #include<math.h> int sushu(int x) { int j; for(j=2;j<=sqrt(x);j++) if(x%j==0) return 0; return 1; } int main() { int s,n,i; scanf("%d",&s); w
https://leetcode.com/problems/binary-tree-postorder-traversal/description/ 给一种容易理解的写法: class Solution {public:vector<int> postorderTraversal(TreeNode* root) {stack<TreeNode*> sta;unordered_set< Tre
LeetCode刷题笔记第145题:二叉树的后序遍历 题目: 给定一棵二叉树的根节点 root ,返回其节点值的后序遍历 。 想法: 后序遍历的是通过对树经过“左右根”的顺序进行遍历。使用递归的方式,先遍历左子树,再遍历右子树,最后遍历根,完成对二叉树的后序遍历。 # Definition for a binary tree node.# class TreeNode:# d
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1\2/3 return [3,2,1]. Note: Recursive solution is trivial, could you do it
前序遍历_迭代法 public List<Integer> preorderTraversal(TreeNode root){List<Integer> result = new ArrayList<>();if(root == null) return result;Deque<TreeNode> stack = new ArrayDeque();stack.push(root);while(