/** * Definition for a binary tree node. * class TreeNode { * public $val = null; * public $left = null; * public $right = null; * function __construct($value) { $this->val = $value; } * } */ class Solution { /** * @param TreeNode $root * @return Integer[] */ public $res ; function inorderTraversal($root) { $this->res = array(); $this->LTR($root) ; return $this->res ; } function LTR($r){ if( $r->left != null ){ $this->LTR($r->left) ; } array_push($this->res,$r->val) ; if( $r->right !=null ){ $this->LTR($r->right) ; } } } |