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

    /**
     * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     TreeNode *left;
     *     TreeNode *right;
     *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
     * };
     */
    class Solution {
    public:
        vector<int> inorderTraversal(TreeNode* root) {
            vector<int> v;
            if(root==NULL) return v;
            if(root->left==NULL && root->right==NULL) {
                v.push_back(root->val);
                return v;
            }
    
            if(root->left)
                 v=inorderTraversal(root->left);
    
            v.push_back(root->val);
    
             if(root->right){
                 vector<int> vv;
                 vv=inorderTraversal(root->right); 
                 for(int i=0;i<vv.size();i++){
                     v.push_back(vv[i]);
                 }
             }
             return v;
        }
    };
  • 相关阅读:
    IEnumerator & IEnumerable
    GameObject.Active
    Unity3D的四种坐标系
    gvim
    Platform Dependent Compilation
    delegate
    new 约束
    UIPanel
    UIButton
    UISprite
  • 原文地址:https://www.cnblogs.com/julie-yang/p/4688138.html
Copyright © 2011-2022 走看看