链表
Data Structures & Algorithms · 23 notes
- Swap Nodes in Pairshistorical
Given a linked list, swap every two adjacent nodes and return the head of the modified list. You must solve the problem without modifying node values (only node links may be changed).
- Reverse Linked List IIhistorical
Given a singly linked list and positions left and right, reverse the nodes in that range and return the updated list.
- Reverse Nodes in k-Grouphistorical
Reverse the nodes of the given linked list in groups of k and return the resulting list. If the number of nodes is not a multiple of k, leave the remaining nodes at the end unchanged.
- Add Two Numbershistorical
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each node stores a single digit.
- Remove Duplicates from Sorted List IIhistorical
Given the head head of a sorted linked list, delete all nodes whose values are duplicated, leaving only values that appear once. Return the sorted linked list.
- Remove Duplicates from Sorted Listhistorical
Given the head head of a sorted linked list, delete duplicate elements so that each value appears only once. Return the sorted linked list.
- Remove Nth Node From End of Listhistorical
Given a linked list, remove the nth node from the end and return the head of the list. For example, given the linked list: 1->2->3->4->5, n = 2. after removing the nth node from the end, the list becomes 1->2->3->5.
- Linked List Cycle IIhistorical
Given a linked list, return the first node where the cycle begins. If the list has no cycle, return null.
- Rotate Listhistorical
Given the head head of a linked list, rotate the list to the right by k positions.
- Linked List Cycle IIhistorical
Given a linked list, return the first node where the cycle begins. If the list has no cycle, return null.
- Intersection of Two Linked Listshistorical
Write a program that finds the first node at which two singly linked lists intersect.
- Reorder Listhistorical
Reorder a singly linked list by alternating nodes from the beginning and end, changing links without modifying node values.
- Partition Listhistorical
Given the head head of a linked list and a value x, partition the list so that all nodes with values less than x come before nodes with values greater than or equal to x.
- Merge k Sorted Listshistorical
Merge k sorted linked lists into one sorted linked list. Analyze and describe the complexity.
- Merge Two Sorted Listshistorical
Merge two sorted linked lists into one new sorted linked list and return it. The new list is formed by splicing together all nodes from the two given lists.
- Odd Even Linked Listhistorical
Given the head head of a singly linked list, group all nodes at odd positions together followed by all nodes at even positions, and return the reordered list.
- Sort Listhistorical
Given the head head of a linked list, sort the list in ascending order and return the sorted list.
- Intersection of Two Linked Listshistorical
Write a program that finds the first node at which two singly linked lists intersect.