yokostan / Leetcode-Solutions

Doing exercise on Leetcode. Carry on!
0 stars 3 forks source link

Leetcode #86 Partition List #123

Open yokostan opened 6 years ago

yokostan commented 6 years ago

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.

Example:

Input: head = 1->4->3->2->5->2, x = 3 Output: 1->2->2->4->3->5

Solutions: /**

Points:

  1. My original though contained the low and high lists idea. We optimized the solution here to give them two Fakeheads and to compare the moving head each time with the moving low and high lists.