zoukankan      html  css  js  c++  java
  • leetcode94

    class Solution {
    public:
        vector<int> V;
        void inOrder(TreeNode* node)
        {
            if (node != NULL)
            {
                if (node->left != NULL)
                {
                    inOrder(node->left);
                }
    
                V.push_back(node->val);
    
                if (node->right != NULL)
                {
                    inOrder(node->right);
                }
            }
        }
        vector<int> inorderTraversal(TreeNode* root) {
            inOrder(root);
            return V;
        }
    };

    二叉树的中序遍历。

    补充python版本实现:

     1 class Solution:
     2     def __init__(self):
     3         self.lists = []
     4         
     5     def inOrder(self,root):
     6         if root != None:
     7             if root.left != None:
     8                 self.inorderTraversal(root.left)
     9             self.lists.append(root.val)
    10             if root.right != None:
    11                 self.inorderTraversal(root.right)
    12         
    13         
    14     def inorderTraversal(self, root: 'TreeNode') -> 'List[int]':
    15         self.inOrder(root)
    16         return self.lists
  • 相关阅读:
    win10使用WampServer部署magento
    JavaScript的this详解
    jQuery的css
    jQuery.cssHooks
    jQuery属性
    jQuery选择器
    ajax中的stasus错误详解
    ajax
    js数组中的注意
    js的严格模式
  • 原文地址:https://www.cnblogs.com/asenyang/p/6840337.html
Copyright © 2011-2022 走看看