We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty: 中等
给定一个链表,删除链表的倒数第 _n _个节点,并且返回链表的头结点。
示例:
给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点后,链表变为 1->2->3->5.
说明:
给定的 n 保证是有效的。
进阶:
你能尝试使用一趟扫描实现吗?
Language: JavaScript
/** * @param {ListNode} head * @param {number} n * @return {ListNode} */ var removeNthFromEnd = function (head, n) { // 定义一个哑节点 dummy,1,2,3,4,5 let dummy = { next: head }; let left = dummy; let right = head; // right: 3 while (n--) { right = right.next; } // right: null left: 3 while (right) { right = right.next; left = left.next; } // left.next = 5 left.next = left.next.next; return dummy.next; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
19. 删除链表的倒数第N个节点
Difficulty: 中等
给定一个链表,删除链表的倒数第 _n _个节点,并且返回链表的头结点。
示例:
说明:
给定的 n 保证是有效的。
进阶:
你能尝试使用一趟扫描实现吗?
思路
Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: