思路: 1. 空間復雜度為 o(n) 解法. 創建兩個鏈表, 分別記錄大於 x 和小於 x 的節點, 最后合並 2. o(1) 的空間復雜度解法. 四個指針, 分別指向小於 x 部分鏈表的頭, 尾 ...
原題地址:https: oj.leetcode.com problems partition list 題意: 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 th ...
2014-06-12 09:38 0 2671 推薦指數:
思路: 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 ...
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 ...
原題地址:https://oj.leetcode.com/problems/rotate-list/ 題意: Given a list, rotate the list to the right by k places, where k is non-negative. ...
原題地址:http://oj.leetcode.com/problems/sort-list/ 題意:鏈表的排序。要求:時間復雜度O(nlogn),空間復雜度O(1)。 解題思路:由於題目對時間復雜度和空間復雜度要求比較高,所以查看了各種解法,最好的解法就是歸並排序,由於鏈表在歸並操作時 ...
原題地址:http://oj.leetcode.com/problems/reorder-list/ 題意: Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You ...
原題地址:http://oj.leetcode.com/problems/linked-list-cycle/ 題意:判斷鏈表中是否存在環路。 解題思路:快慢指針技巧,slow指針和fast指針開始同時指向頭結點head,fast每次走兩步,slow每次走一步。如果鏈表不存在環,那么fast ...