牛客题霸 NC23 划分链表
生活随笔
收集整理的這篇文章主要介紹了
牛客题霸 NC23 划分链表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.nowcoder.com/practice/1dc1036be38f45f19000e48abe00b12f
解決方案
Go
func partition(head *ListNode, x int) *ListNode {// write code herereturn solve(head, nil, nil, x) }func solve(head *ListNode, pre *ListNode, h *ListNode, x int) *ListNode {if head == nil {return h}if head.Val >= x {if pre == nil {return solve(head.Next, head, head, x)} else {next := head.Nextpre.Next = headhead.Next = nilreturn solve(next, head, h, x)}} else {head.Next = solve(head.Next, pre, h, x)return head} }參考文章
總結
以上是生活随笔為你收集整理的牛客题霸 NC23 划分链表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 云效 Flow——Java构建并通过云效
- 下一篇: 牛客题霸 NC24 删除有序链表中重复的