This commit is contained in:
krahets
2023-12-22 02:57:23 +08:00
parent 0039563806
commit 767f5029da
13 changed files with 15 additions and 14 deletions

View File

@@ -875,9 +875,10 @@ comments: true
```c title="linked_list.c"
/* 访问链表中索引为 index 的节点 */
ListNode *access(ListNode *head, int index) {
while (head && head->next && index) {
for (int i = 0; i < index; i++) {
if (head == NULL)
return NULL;
head = head->next;
index--;
}
return head;
}