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
876. 链表的中间结点
参考题解: https://leetcode.cn/problems/middle-of-the-linked-list/solution/lian-biao-de-zhong-jian-jie-dian-by-leetcode-solut/
var middleNode = function (head) { // 统计链表的节点数 let count = 1; let currentHead = head; while (currentHead.next) { count++; currentHead = currentHead.next; } const middleNodeIndex = Math.floor(count / 2) + 1; let secondHead = head; for (let i = 1; i <= count; i++) { if (i === middleNodeIndex) { return secondHead } else { secondHead = secondHead.next } } };
var middleNode = function(head) { slow = fast = head; while (fast && fast.next) { slow = slow.next; fast = fast.next.next; } return slow; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
876. 链表的中间结点
参考题解: https://leetcode.cn/problems/middle-of-the-linked-list/solution/lian-biao-de-zhong-jian-jie-dian-by-leetcode-solut/
通用解法
快慢指针
The text was updated successfully, but these errors were encountered: