File tree Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ package main
55 * @Date: 2019-09-22 15:05:54
66 * @LastEditors: wangtongli
778- * @LastEditTime: 2019-09-22 16:17:14
8+ * @LastEditTime: 2019-09-22 23:40:37
99 */
1010
1111import (
Original file line number Diff line number Diff line change 11package main
22
33/*
4- * @Description: "sqrt function"
4+ * @Description: 69.Sqrt(x)
55 * @Date: 2019-09-22 16:08:09
66 * @LastEditors: wangtongli
778- * @LastEditTime: 2019-09-22 16:21:02
8+ * @LastEditTime: 2019-09-22 23:42:13
99 */
10-
1110func mySqrt (x int ) int {
12- return 0
11+ var i , value int
12+ //初始化,执行一次;条件,必须;其他
13+ for value < x {
14+ i ++
15+ value = i * i
16+ }
17+ if value > x {
18+ return i - 1
19+ }
20+ return i
1321}
Original file line number Diff line number Diff line change 1+ package main
2+
3+ /*
4+ * @Description: 69.Sqrt(x)
5+ * @Date: 2019-09-22 23:38:59
6+ * @LastEditors: wangtongli
7+ 8+ * @LastEditTime: 2019-09-22 23:41:55
9+ */
10+ func mySqrt1 (x int ) int {
11+ max , min := x , 0
12+ if x == 1 {
13+ return 1
14+ }
15+ for max - min > 1 {
16+ mid := (min + max ) / 2
17+ if mid * mid > x {
18+ max = mid
19+ } else {
20+ min = mid
21+ }
22+ }
23+ return min
24+ }
You can’t perform that action at this time.
0 commit comments