MOST BAD SOLUTION...I THINK THIS ONE IS MOST HARD FOR ME..


  • 0
    S

    HERE IS MY CODE.....

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode(int x) { val = x; }
     * }
     */
    public class Solution {
        List<Integer> data=new ArrayList<Integer>();
        public void getdiff(TreeNode root){
            if(root==null) return;
            getdiff(root.left);
          data.add(root.val);
            getdiff(root.right);
        }
        public int getMinimumDifference(TreeNode root) {
            getdiff(root);
            int min=Integer.MAX_VALUE;
            for(int i=0;i<data.size()-1;i++){
                int temp=Math.abs(data.get(i)-data.get(i+1));
                if(temp<min)
                    min=temp;
            }
            return min;
            
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.