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

2018-11-16.md的algorithm #2

Open
MarsForever opened this issue Nov 25, 2018 · 0 comments
Open

2018-11-16.md的algorithm #2

MarsForever opened this issue Nov 25, 2018 · 0 comments

Comments

@MarsForever
Copy link

MarsForever commented Nov 25, 2018

第一个if文改成下面这种形式,避免了最后一个字母和target是同值的情况

//如果 target大于等于数组中最大的字母大,那么返回第一个字母
if (target >= letters[len-1]) {
       return letters[0];
}

那么下面这一步可以省略

if (mid + 1 == len) {
       return letters[0];
 }

大概可以快1ms左右

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant