add new solutions
This commit is contained in:
parent
d798d5e8c9
commit
886b5e0a8e
34 changed files with 1164 additions and 0 deletions
30
solutions/0/q86/solution.go
Normal file
30
solutions/0/q86/solution.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package q86
|
||||
|
||||
type ListNode struct {
|
||||
Val int
|
||||
Next *ListNode
|
||||
}
|
||||
|
||||
func partition(head *ListNode, x int) *ListNode {
|
||||
stub := &ListNode{Next: head}
|
||||
before := stub
|
||||
for before.Next != nil && before.Next.Val < x {
|
||||
before = before.Next
|
||||
}
|
||||
|
||||
for p := before.Next; p != nil && p.Next != nil; {
|
||||
if p.Next.Val < x {
|
||||
move := p.Next
|
||||
p.Next = move.Next
|
||||
|
||||
move.Next = before.Next
|
||||
before.Next = move
|
||||
before = move
|
||||
} else {
|
||||
p = p.Next
|
||||
}
|
||||
}
|
||||
return stub.Next
|
||||
}
|
||||
|
||||
var _ = partition
|
||||
Loading…
Add table
Add a link
Reference in a new issue