86. Partition List

Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.

You should preserve the original relative order of the nodes in each of the two partitions.

For example,

Given 1->4->3->2->5->2 and x = 3,

return 1->2->2->4->3->5.

给一个链表,和一个整数x, 要求把所有比x小的节点放到前边,把比x大的节点放到后边。


代码:


参考代码

解题思路:弄一个 less链表和greate链表,遍历head链表,对应的大小值分别给less和greater链表,最后把greate链表链接在less 的后边。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容