Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0fa1ef9

Browse files
🐱(binary-search): 69. x 的平方根
1 parent aeab6a1 commit 0fa1ef9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎docs/algorithm/research/binary-search/README.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ class Solution(object):
219219

220220
二分查找,注意边界值的处理。
221221

222+
<!-- tabs:start -->
223+
224+
#### **Python**
225+
222226
```python
223227
class Solution(object):
224228
def mySqrt(self, x):
@@ -245,6 +249,30 @@ class Solution(object):
245249

246250
```
247251

252+
#### **Go**
253+
254+
```go
255+
func mySqrt(x int) int {
256+
left := 0
257+
right := x
258+
ans := 0
259+
for left <= right {
260+
mid := (left + right) / 2
261+
// fmt.Println(mid)
262+
if mid * mid <= x {
263+
// 可能出现结果
264+
ans = mid
265+
left = mid + 1
266+
} else {
267+
right = mid - 1
268+
}
269+
}
270+
return ans
271+
}
272+
```
273+
274+
<!-- tabs:end -->
275+
248276
ps:看评论有很秀的牛顿迭代法,有空研究下。
249277

250278
## 74. 搜索二维矩阵

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /