private static void helper(LeetCode783TreeNode root) { if (root == null) { return; } helper(root.left); if (pre != -1) { result = Math.Min(result, root.val - pre); } pre = root.val; helper(root.right); }
public LeetCode783TreeNode(int val = 0, LeetCode783TreeNode left = null, LeetCode783TreeNode right = null) { this.val = val; this.left = left; this.right = right; }
public static int MinDiffInBST(LeetCode783TreeNode root) { helper(root); return(result); }