Q86: Partition List
Last updated
Was this helpful?
Last updated
Was this helpful?
直达:
Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.
You should preserve the original relative order of the nodes in each of the two partitions.
For example,
Given1->4->3->2->5->2
andx= 3,
return1->2->2->4->3->5
.
给定一个整数链表和一个整数x,将小于x的移到新链表的左边,大于等于的移到右边,保证链表的同一部分的顺序不变,如上图。
初始化两个链表,一个保存小于x的,一个保存大于等于x的,最后重新连接两个链表即可。