private static void Helper(LeetCode285TreeNode root) { if (root == null) { return; } Helper(root.left); list.Add(root); Helper(root.right); }
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); }