From 27f8efa24c9d43b911fc7c05a7182508d50365cd Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Mon, 21 Nov 2022 23:12:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E8=AE=BE=E8=AE=A1=E9=93=BE=E8=A1=A8?= =?UTF-8?q?=E7=9A=84C++=E4=BB=A3=E7=A0=81=E9=83=A8=E5=88=86=EF=BC=8CaddAtI?= =?UTF-8?q?ndex=E6=96=B9=E6=B3=95=E4=B8=AD=EF=BC=8C=E9=92=88=E5=AF=B9index?= =?UTF-8?q?=20<=200=20=E7=9A=84=E6=83=85=E5=86=B5=E7=BA=A0=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0707.设计链表.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/problems/0707.设计链表.md b/problems/0707.设计链表.md index 1264983b..9461e263 100644 --- a/problems/0707.设计链表.md +++ b/problems/0707.设计链表.md @@ -108,9 +108,12 @@ public: // 如果index大于链表的长度,则返回空 // 如果index小于0,则置为0,作为链表的新头节点。 void addAtIndex(int index, int val) { - if (index > _size || index < 0) { + if (index > _size) { return; } + if (index < 0) { + index = 0; + } LinkedNode* newNode = new LinkedNode(val); LinkedNode* cur = _dummyHead; while(index--) {