Why my solution get a Time Limit Exceeded feedback?

  • 0

    I do not see any difference between the top solution and mine, but why am I still get Time Limit Exceeded feedback? Please help....

    /* The isBadVersion API is defined in the parent class VersionControl.
          boolean isBadVersion(int version); */
    public class Solution extends VersionControl {
        public int firstBadVersion(int n) {
            int left = 0;
            int right = n-1;
            while (right - left != 1) {
                int middle = (int) ((left + right)/2.0);
                if (isBadVersion(middle) == true) {
                    right = middle;
                } else {
                    left = middle;
            return right;

Log in to reply

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