Skip to content

Commit

Permalink
first bad version
Browse files Browse the repository at this point in the history
  • Loading branch information
meooxx committed Apr 25, 2023
1 parent 96e90de commit 37ff32a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions firstBadVersion/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

func isBadVersion(version int) bool

/**
* Forward declaration of isBadVersion API.
* @param version your guess about first bad version
* @return true if current version is bad
* false if current version is good
* func isBadVersion(version int) bool;
*/

func firstBadVersion(n int) int {
left := 0
right := n
for left < right {
mid := (right-left)/2 + left
// isBad := isBadVersion(mid)
if isBadVersion(mid) {
right = mid
} else {
left = mid + 1
}
}
return left
}

0 comments on commit 37ff32a

Please sign in to comment.