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
给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前。
你应当保留两个分区中每个节点的初始相对位置。
输入: head = 1->4->3->2->5->2, x = 3 输出: 1->2->2->4->3->5
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/partition-list
/** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func partition(head *ListNode, x int) *ListNode { beforeTmp := &ListNode{} afterTmp := &ListNode{} before := beforeTmp after := afterTmp for head != nil { if head.Val < x { beforeTmp.Next = head beforeTmp = beforeTmp.Next } else { afterTmp.Next = head afterTmp = afterTmp.Next } head = head.Next } afterTmp.Next = nil beforeTmp.Next = after.Next return before.Next }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前。
你应当保留两个分区中每个节点的初始相对位置。
示例:
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/partition-list
The text was updated successfully, but these errors were encountered: