存取效率
Array > LinkedList
LinkedList要从头开始移动指针而Array是randomaccess
插入元素:LinkedList更灵活
LinkedList练习
Reverse LinkedList
翻转LinkedList
1->2->3->4->null
4->3->2->1->null
1 | //0->1->2->3->4 |
Reverse Linked ListII
Reverse a linked list from position m to n.
Notice
Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list.
1 | Example |
1 | public ListNode reverseBetween(ListNode head, int m, int n) { |
Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.
You may not alter the values in the nodes, only nodes itself may be changed.
Only constant memory is allowed.
1 | Example |
1 | public ListNode reverseKGroup(ListNode head, int k) { |