/* The isBadVersion API is defined in the parent class VersionControl. bool IsBadVersion(int version); */ public class Solution : VersionControl { public int FirstBadVersion(int n) { var start = 1; var end = n; while (start < end) { var mid = start + (end - start) / 2; if (!IsBadVersion(mid)) { start = mid + 1; } else { end = mid; } } return start; } }
https://leetcode.com/problems/first-bad-version/#/description