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

Java 中的数组部分,插入元素的时候好像存在问题 #60

Closed
bigrotor187 opened this issue Oct 13, 2018 · 1 comment
Closed

Comments

@bigrotor187
Copy link

if (index<0 || index>=count) return false;

刚开始插入元素的时候, index >= count 就会出问题,因为 count 初始化为 0,所以即使从头开始插入(即 index = 0),也插入不成功。换句话说根本插入不了元素,我觉得应该改成将 index >= count 改成 index > count:

if (index<0 || index > count) return false;

不知道理解对不对。

@kimmazhenxin
Copy link

是的,我一开始也是这样子,因为初始化时候元素为0,后来去掉了“=”就ok了

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

2 participants