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
No description provided.
The text was updated successfully, but these errors were encountered:
// 反转链表n个结点的方法 var __reverseN = function(head, n) { if (n == 1) return head let tail = head.next, p = __reverseN(head.next, n - 1) head.next = tail.next tail.next = head return p } // 判断是否需要进行反转,如果剩余结点个数小于n,直接返回head var reverseN = function(head, n) { let cut = n, p = head while(--n && p) p = p.next if (!p) return head return __reverseN(head, cut) } // 定义一个虚头ret指向head,p指针指向ret),q指针指向p.next(头节点翻转后变尾节点) // 令p.next指向反转后的结点,如果和q相等,则证明反转结束,返回ret.next // 如果p.next和q不相等,则证明反转结点成功,准备进行下一轮反转,让p指向q,q指向q.next var reverseKGroup = function(head, k) { let ret = new ListNode(null, head), p = ret, q = p.next while((p.next = reverseN(q, k)) != q) { p = q q = q.next } return ret.next };
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: