mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
Update the access() function of linked_list
This commit is contained in:
@ -29,9 +29,9 @@ public class linked_list {
|
||||
/* 访问链表中索引为 index 的结点 */
|
||||
static ListNode access(ListNode head, int index) {
|
||||
for (int i = 0; i < index; i++) {
|
||||
head = head.next;
|
||||
if (head == null)
|
||||
return null;
|
||||
head = head.next;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user