zoukankan      html  css  js  c++  java
  • 94_Binary Tree Inorder Traversal

    Given a binary tree, return the inorder traversal of its nodes' values.

    For example:
    Given binary tree {1,#,2,3},

       1
        
         2
        /
       3
    

    return [1,3,2].

    中序遍历,顺序为:左、根节点、右

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     public int val;
     *     public TreeNode left;
     *     public TreeNode right;
     *     public TreeNode(int x) { val = x; }
     * }
     */
    public class Solution {
        public void InOrder(TreeNode root, IList<int> path)
        {
            if(root != null)
            {
                InOrder(root.left, path);
                path.Add(root.val);
                InOrder(root.right, path);
            }
        }
        
        public IList<int> InorderTraversal(TreeNode root) {
            List<int> result = new List<int>();
            InOrder(root, result);
            return result;
        }
    }
  • 相关阅读:
    go 错误处理策略
    git merge
    oracle
    使用PHPExcel导入数据库,date数据的问题
    PhpWord使用
    ThinkPHP
    Memcache
    没用过docker就out了
    TCP三次挥手四次协议
    数据分析
  • 原文地址:https://www.cnblogs.com/Anthony-Wang/p/5091003.html
Copyright © 2011-2022 走看看