Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Nov 22, 2023
1 parent fa11b36 commit deb320e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions leetcode/69.Sqrt_x/sqrt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"
)

func mySqrt(x int) int {
if x < 2 {
return x
}

l, r := 0, x

for l < r {
mid := l + (r-l+1)>>1
if mid <= x/mid {
l = mid
} else {
r = mid - 1
}
}

return l
}

func main() {
x := 4
fmt.Println(mySqrt(x))
}

0 comments on commit deb320e

Please sign in to comment.