We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bbace09 commit 853e4e9Copy full SHA for 853e4e9
solution/0069.Sqrt(x)/Solution.go
@@ -0,0 +1,28 @@
1
+/**
2
+ * @lc app=leetcode.cn id=69 lang=golang
3
+ * Accepted
4
+ * 1017/1017 cases passed (0 ms)
5
+ * Your runtime beats 100 % of golang submissions
6
+ * Your memory usage beats 25.49 % of golang submissions (2.2 MB)
7
+ */
8
+
9
+func mySqrt(x int) int {
10
+ if x == 0 || x == 1 {
11
+ return x
12
+ }
13
+ l, r, t := 1, x, 0
14
+ m := (l + r) / 2
15
+ for l != m {
16
+ t = m * m
17
+ if t == x {
18
+ return m
19
20
+ if t < x {
21
+ l = m
22
+ } else {
23
+ r = m
24
25
+ m = (l + r) / 2
26
27
28
+}
0 commit comments