/** * 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 bool IsValidBST(TreeNode root) { var result = new List(); Travel(root, ref result); for(var i = 0;i < result.Count - 1; i++){ if(result[i+1] <= result[i]){ return false; } } return true; } private void Travel(TreeNode node ,ref List result) { if(node == null){ return; } Travel(node.left, ref result); result.Add(node.val); Travel(node.right, ref result); } }