Skip to content

Commit ba0e3f2

Browse files
authored
docs: add Open in GitHub Codespaces badge (#2117)
1 parent b13676c commit ba0e3f2

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@
197197
  <a href="https://github.com/doocs/leetcode"><img src="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/leetcode@main/images/how-to-contribute.svg" alt="how-to-contribute"></a>
198198
</p>
199199

200-
[Gitpod.io](https://www.gitpod.io) 是一个免费的在线开发环境,你也可以使用它参与本项目。
201-
202-
<a href="https://gitpod.io/#https://github.com/doocs/leetcode" target="_blank" alt="Open in Gitpod"><img src="https://gitpod.io/button/open-in-gitpod.svg"></a>
200+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=149001365&machine=basicLinux32gb&location=SoutheastAsia)
203201

204202
## Stars 趋势
205203

README_EN.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ I'm looking for long-term contributors/partners to this repo! Send me [PRs](http
191191
  <a href="https://github.com/doocs/leetcode"><img src="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/leetcode@main/images/how-to-contribute.svg" alt="how-to-contribute"></a>
192192
</p>
193193

194-
You can also contribute to [doocs/leetcode](https://github.com/doocs/leetcode) using [Gitpod.io](https://www.gitpod.io), a free online dev environment with a single click.
195-
196-
<a href="https://gitpod.io/#https://github.com/doocs/leetcode" target="_blank" alt="Open in Gitpod"><img src="https://gitpod.io/button/open-in-gitpod.svg"></a>
194+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=149001365&machine=basicLinux32gb&location=EastUs)
197195

198196
## Stargazers over time
199197

basic/searching/BinarySearch/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ int search(int left, int right) {
4242
}
4343
```
4444

45-
我们做二分题目时,可以按照以下步骤
45+
做二分题目时,可以按照以下套路
4646

47-
1. 写出循环条件`while (left < right)`,注意是 `left < right`,而非 `left <= right`
48-
1. 循环体内,先无脑写出 `mid = (left + right) >> 1`
49-
1. 根据具体题目,实现 `check()` 函数(有时很简单的逻辑,可以不定义 `check`),想一下究竟要用 `right = mid`(模板 1) 还是 `left = mid`(模板 2);
50-
- 如果 `right = mid`,那么无脑写出 else 语句 `left = mid + 1`,并且不需要更改 mid 的计算,即保持 `mid = (left + right) >> 1`
51-
- 如果 `left = mid`,那么无脑写出 else 语句 `right = mid - 1`,并且在 mid 计算时补充 +1,即 `mid = (left + right + 1) >> 1`
52-
1. 循环结束时,left 与 right 相等。
47+
1. 写出循环条件 $left < right$
48+
1. 循环体内,不妨先写 $mid = \lfloor \frac{left + right}{2} \rfloor$
49+
1. 根据具体题目,实现 $check()$ 函数(有时很简单的逻辑,可以不定义 $check$),想一下究竟要用 $right = mid$(模板 $1$) 还是 $left = mid$(模板 $2$);
50+
    - 如果 $right = mid$,那么写出 else 语句 $left = mid + 1$,并且不需要更改 mid 的计算,即保持 $mid = \lfloor \frac{left + right}{2} \rfloor$
51+
    - 如果 $left = mid$,那么写出 else 语句 $right = mid - 1$,并且在 $mid$ 计算时补充 +1,即 $mid = \lfloor \frac{left + right + 1}{2} \rfloor$;
52+
1. 循环结束时,$left$$right$ 相等。
5353

54-
注意,这两个模板的优点是始终保持答案位于二分区间内,二分结束条件对应的值恰好在答案所处的位置。 对于可能无解的情况,只要判断二分结束后的 left 或者 right 是否满足题意即可。
54+
注意,这两个模板的优点是始终保持答案位于二分区间内,二分结束条件对应的值恰好在答案所处的位置。 对于可能无解的情况,只要判断二分结束后的 $left$ 或者 $right$ 是否满足题意即可。
5555

5656
## 例题
5757

basic/searching/BinarySearch/README_EN.md

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Algorithm Templates
44

5+
The essence of binary search is not "monotonicity", but "boundary". As long as a certain property is found that divides the entire interval into two, the boundary point can be found using binary search.
6+
57
### Template 1
68

79
```java
@@ -40,6 +42,17 @@ int search(int left, int right) {
4042
}
4143
```
4244

45+
When doing binary search problems, you can follow the following routine:
46+
47+
1. Write out the loop condition $left < right$;
48+
2. Inside the loop, you might as well write $mid = \lfloor \frac{left + right}{2} \rfloor$ first;
49+
3. According to the specific problem, implement the $check()$ function (sometimes the logic is very simple, you can not define $check$), think about whether to use $right = mid$ (Template $1$) or $left = mid$ (Template $2$);
50+
- If $right = mid$, then write the else statement $left = mid + 1$, and there is no need to change the calculation of $mid$, that is, keep $mid = \lfloor \frac{left + right}{2} \rfloor$;
51+
- If $left = mid$, then write the else statement $right = mid - 1$, and add +1 when calculating $mid$, that is, $mid = \lfloor \frac{left + right + 1}{2} \rfloor$;
52+
4. When the loop ends, $left$ equals $right$.
53+
54+
Note that the advantage of these two templates is that they always keep the answer within the binary search interval, and the value corresponding to the end condition of the binary search is exactly at the position of the answer. For the case that may have no solution, just check whether the $left$ or $right$ after the binary search ends satisfies the problem.
55+
4356
## Examples
4457

4558
- [Find First and Last Position of Element in Sorted Array](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md)

0 commit comments

Comments
 (0)