zoukankan      html  css  js  c++  java
  • Binary Tree Preorder Traversal

    /**
     * Definition for binary tree
     * struct TreeNode {
     *     int val;
     *     TreeNode *left;
     *     TreeNode *right;
     *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
     * };
     */
     /*
     求二叉树的前序遍历序列
     递归解法,下次写下迭代的
     */
    class Solution {
    public:
        vector<int> res;
        void dfs(TreeNode *root){
            if(!root) return;
            res.push_back(root->val);
            dfs(root->left);
            dfs(root->right);
        }
        vector<int> preorderTraversal(TreeNode *root) {
            dfs(root);
            return res;
        }
    };
  • 相关阅读:
    PHP小技巧
    PHP Ajax跨域解决
    单点登录
    Linux 常用命令
    php面向对象--继承
    vueDemo
    vueSource
    vuex
    Vue.js
    关于前后端分离
  • 原文地址:https://www.cnblogs.com/llei1573/p/4342891.html
Copyright © 2011-2022 走看看