Update 0707.设计链表.md
This commit is contained in:
parent
d0814a723c
commit
0c6b1db35c
|
|
@ -106,12 +106,9 @@ public:
|
||||||
// 如果index大于链表的长度,则返回空
|
// 如果index大于链表的长度,则返回空
|
||||||
// 如果index小于0,则置为0,作为链表的新头节点。
|
// 如果index小于0,则置为0,作为链表的新头节点。
|
||||||
void addAtIndex(int index, int val) {
|
void addAtIndex(int index, int val) {
|
||||||
if (index > _size) {
|
if (index > _size || index < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (index < 0) {
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
LinkedNode* newNode = new LinkedNode(val);
|
LinkedNode* newNode = new LinkedNode(val);
|
||||||
LinkedNode* cur = _dummyHead;
|
LinkedNode* cur = _dummyHead;
|
||||||
while(index--) {
|
while(index--) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue