예제 #1
0
 private static void Helper(LeetCode285TreeNode root)
 {
     if (root == null)
     {
         return;
     }
     Helper(root.left);
     list.Add(root);
     Helper(root.right);
 }
예제 #2
0
        public static LeetCode285TreeNode InorderSuccessor(LeetCode285TreeNode root, LeetCode285TreeNode p)
        {
            if (root == null || p == null)
            {
                return(null);
            }
            Helper(root);

            var index = list.FindIndex(x => x.val == p.val);

            return(index >= 0 && (index + 1 < list.Count) ? list[index + 1] : null);
        }