Skip to content

Latest commit

 

History

History
18 lines (16 loc) · 809 Bytes

86.md

File metadata and controls

18 lines (16 loc) · 809 Bytes

LeetCode 86 Partition List——medium

Given a linked list and a value x, partition it such that all nodes less than xcome before nodes greater than or equal to x.
You should preserve the original relative order of the nodes in each of the two partitions.
Example:
Input: head = 1->4->3->2->5->2, x = 3
Output: 1->2->2->4->3->5
思路:
1、因为链表是指针关系、所以可以增加两个链表头small、big分别用来记录<x 和>=x两部分
最后再将两部分连接起来,别得到了answer
2、这其中要随时记录最后的节点、所以还要增加两个临时节点curs、curb用来不断增加后面的节点
3、最后将small连接上big、并且把big链表最后节点的next赋值为null