https://github.com/vogo/goalg
golang algorithm implement for leetcode and data structures
https://github.com/vogo/goalg
algorithms data-structure golang leetcode
Last synced: 4 months ago
JSON representation
golang algorithm implement for leetcode and data structures
- Host: GitHub
- URL: https://github.com/vogo/goalg
- Owner: vogo
- License: apache-2.0
- Created: 2020-06-03T00:24:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-08T08:17:08.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T13:19:05.636Z (almost 2 years ago)
- Topics: algorithms, data-structure, golang, leetcode
- Language: Go
- Homepage:
- Size: 75.2 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goalg
[](https://travis-ci.org/vogo/goalg)
[](https://codecov.io/gh/vogo/goalg)
[](https://godoc.org/github.com/vogo/goalg)
[](https://goreportcard.com/report/github.com/vogo/goalg)

## 二分查找
**核心思想**:
- 给定排序的数组,选定中间位置,和目标值比较;
- 如果小于目标值,则在左侧继续查找;
- 如果大于目标值,则在右侧继续查找。
**算法关键**:
- mid在边界情况时取值: `r = l + 1` 情况下, 即左右指针相邻的情况, `mid = l = l + (r - l)/2`, `mid = r = l + (r - l + 1)/2`;
- 避免死循环: 确保以上边界情况 l 或 r 的值变化后下一次循环mid取得不同的值,或能跳出循环。