思路: 1. 空间复杂度为 o(n) 解法. 创建两个链表, 分别记录大于 x 和小于 x 的节点, 最后合并 2. o(1) 的空间复杂度解法. 四个指针, 分别指向小于 x 部分链表的头, 尾 ...
题目: 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 ...
2014-07-23 10:21 0 3863 推荐指数:
思路: 1. 空间复杂度为 o(n) 解法. 创建两个链表, 分别记录大于 x 和小于 x 的节点, 最后合并 2. o(1) 的空间复杂度解法. 四个指针, 分别指向小于 x 部分链表的头, 尾 ...
原题地址:https://oj.leetcode.com/problems/partition-list/ 题意: Given a linked list and a value x, partition it such that all nodes less than x come ...
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 ...
题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k ...
题目: Sort a linked list in O(n log n) time using constant space complexity. 题解: 考虑到要求用O(nlogn)的时间复杂度和constant space complexity来sort list,自然而然想到 ...
题目: Sort a linked list using insertion sort. 题解: Insertion Sort就是把一个一个元素往已排好序的list中插入的过程。 初始时,sorted list是空,把一个元素插入sorted list中。然后,在每一次插入过程中,都是 ...
题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m ...
题目: Given a binary tree, flatten it to a linked list in-place. For example, Given The flattened tree should look like: 1 TreeNode ...