Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Anand Nageshwar Kumar
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