mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2026-03-11 04:14:41 +00:00
添加Go语言题解
This commit is contained in:
@@ -187,3 +187,31 @@ class Solution {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Go Code:
|
||||
|
||||
```go
|
||||
func partition(head *ListNode, x int) *ListNode {
|
||||
big, small := &ListNode{}, &ListNode{}
|
||||
headBig, headSmall := big, small
|
||||
temp := head
|
||||
for temp != nil {
|
||||
// 分开存
|
||||
if temp.Val < x {
|
||||
small.Next = temp
|
||||
small = small.Next
|
||||
} else {
|
||||
big.Next = temp
|
||||
big = big.Next
|
||||
}
|
||||
temp = temp.Next
|
||||
}
|
||||
// 最后一个节点指向nil
|
||||
big.Next = nil
|
||||
// 存小数的链表和存大数的连起来
|
||||
small.Next = headBig.Next
|
||||
return headSmall.Next
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user