Back to course home
0% completed
Vote For New Content
C# O(1) Space
Anand Nageshwar Kumar
Apr 30, 2024
public class Solution { int result = Int32.MaxValue; int? prev = null; public int GetMinimumDifference(TreeNode root) { DFS(root); return result; } private void DFS(TreeNode root) { if(root == null) return; DFS(root.left); if(prev.HasValue) result = Math.Min(result, root.val - prev.Value); prev = root.val; DFS(root.right); } }
1
0
Comments
Comments
On this page