Is it a bug?


  • 0
    L

    [0_1494145965853_J6VIT6U(4~T8BWH15)YE]EC.png](/uploads/files/1494145963803-j6vit6u-4-t8bwh15-ye-ec.png)

    code :
    /**

    • Definition for a binary tree node.
    • struct TreeNode {
    • int val;
      
    • struct TreeNode *left;
      
    • struct TreeNode *right;
      
    • };
      /
      int A[1000000];
      int length=0;
      int travel(struct TreeNode
      root)
      {
      if(root->left!=NULL)
      {
      travel(root->left);
      }
      A[length]=root->val;
      length++;
      if(root->right!=NULL)
      {
      travel(root->right);
      }
      return 0;
      }
      int getMinimumDifference(struct TreeNode* root) {
      travel(root);
      int min=abs(A[0]-A[1]);
      for(int i=1;i<length-1;i++)
      {
      if(min>abs(A[i]-A[i+1]))
      {
      min=abs(A[i]-A[i+1]);
      }
      }
      return min;
      }

  • 0
    L
    This post is deleted!

  • 0
    L
    This post is deleted!

  • 0
    L

    @Lancher

    1. Minimum Absolute Difference in BST

    Submission Result:
    Input:[1,null,5,3]
    Output:1
    Expected:2

    Run Code Result:

    Your input
    [1,null,5,3]
    Your answer
    2
    Expected answer
    2

    bug??


  • 0

    Yes, you have a bug.

    And please format your code.


  • 0
    L
    This post is deleted!

Log in to reply
 

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