Skip to content

Instantly share code, notes, and snippets.

@KeshariPiyush24
Created September 21, 2024 05:31
Show Gist options
  • Save KeshariPiyush24/c7085d19c91d28ba5dec9573d77d08ed to your computer and use it in GitHub Desktop.
Save KeshariPiyush24/c7085d19c91d28ba5dec9573d77d08ed to your computer and use it in GitHub Desktop.
278. First Bad Version

Question: 278. First Bad Version

Intution:

Time Complexity: $$O(log(n))$$

Space Complexity: $$O(1)$$

Solution:

public class Solution extends VersionControl {
    public int firstBadVersion(int n) {
        int low = 1;
        int high = n;
        while (low < high) {
            int mid = low + (high - low) / 2;
            if (isBadVersion(mid))
                high = mid;
            else
                low = mid + 1;
        }
        return low;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment