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 aeab6a1 commit 0fa1ef9Copy full SHA for 0fa1ef9
docs/algorithm/research/binary-search/README.md
@@ -219,6 +219,10 @@ class Solution(object):
219
220
二分查找,注意边界值的处理。
221
222
+<!-- tabs:start -->
223
+
224
+#### **Python**
225
226
```python
227
class Solution(object):
228
def mySqrt(self, x):
@@ -245,6 +249,30 @@ class Solution(object):
245
249
246
250
```
247
251
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
248
276
ps:看评论有很秀的牛顿迭代法,有空研究下。
277
278
## 74. 搜索二维矩阵
0 commit comments