本文主要是介绍Golang | Leetcode Golang题解之第86题分隔链表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题解:
func partition(head *ListNode, x int) *ListNode {small := &ListNode{}smallHead := smalllarge := &ListNode{}largeHead := largefor head != nil {if head.Val < x {small.Next = headsmall = small.Next} else {large.Next = headlarge = large.Next}head = head.Next}large.Next = nilsmall.Next = largeHead.Nextreturn smallHead.Next
}
这篇关于Golang | Leetcode Golang题解之第86题分隔链表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!