思路: 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 ...