标签:
题目描述:/** * 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<int>(); 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<int> result) { if(node == null){ return; } Travel(node.left, ref result); result.Add(node.val); Travel(node.right, ref result); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
LeetCode -- Validate Binary Search Tree
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/49188109