Tag: linked list
-
Algorithms 101: Queue Implementation Using Linked List and Array
•
队列的链表实现和数组实现 Queue Implementation Using Linked List and Array 1. 使用链表实现队列 1. Queue Implementation Using Linked List A queue can be implemented using a linked list where each node represents an element in the queue. The head of the linked list represents the front of the queue, and the tail represents…
-
Leetcode: 86 Partition List
•
Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. Example: Input: head = [1,4,3,2,5,2],…
-
Algorithms 101: Preserving Relative Position in Linked List
•
链表分隔问题:保留相对位置 Linked List Partitioning Problem: Preserving Relative Position Given the head of a linked list and a specific value x, the task is to partition the linked list so that all nodes with values less than x appear before nodes with values greater than or equal to x. Additionally, the…
-
LeetCode: 141 Linked List Cycle
•
Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to…
-
LeetCode: 206 Reverse Linked List
•
Given the head of a singly linked list, reverse the list, and return the reversed list. Example: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example: Input: head = [1,2] Output: [2,1] Example: Input: head = [] Output: [] 问题 给定一个单链表的头节点,将链表反转,并返回反转后的链表。 解决方案 1 迭代法 Approach 1 / 方法 1 This solution uses…
-
Algorithms 101: Why Should You Use a Dummy Node
•
为什么要使用哑节点? English: Using a dummy node is a common technique in linked list problems. It involves creating an extra node that is placed before the head of the linked list. Chinese: 使用哑节点是链表问题中常见的技巧。它涉及在链表头节点之前创建一个额外的节点。 English: This dummy node doesn’t hold any useful data for the problem but serves as a useful placeholder…
-
LeetCode: 19 Remove Nth Node From End of linked list
•
Given the head of a linked list, remove the nth node from the end of the list and return its head. Example: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Explanation: The second node from the end is 4, so we remove it and link 3 to 5. Example:…