Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add for/while #64

Open
wants to merge 3 commits into
base: merge
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,45 @@ package-lock.json

编写您想要的代码,特别是在一个团队中有多个开发人员的情况下。这是“自由”原则。


### 💩 构建新项目不需要 README 文档

一开始我们就应该保持。

### 💩 保存不必要的代码

不要删除不用的代码,最多注释掉。

### 💩 递归总比循环好

如果能使用递归解决问题,就不要使用for while等循环。

_Good 👍🏻_

```javascript
int binarySearchRecur(int []a,int target,int low,int high) {
if (low > high) return -1;
int mid = (low + high) + low / 2;
if (a[mid] == target) {
return mid;
}
return (target < a[mid])? binarySearchRecur(a, target, low, mid - 1) :binarySearchRecur(a, target, mid + 1, high);
}
```

_Bad 👎🏻_

```javascript
int binarySearch(int []a,int target) {
int l = 0, h = a.length - 1;
while (l <= h) {
int mid = l+(h-l) / 2;
if (target == a[mid]) return mid;
if (target > a[mid]) {
l = mid + 1;}
else{
h = mid - 1;
}
```