摘要:
题目:Sort a linked list in O(n log n) time using constant space complexity.题解:考虑到要求用O(nlogn)的时间复杂度和constant space complexity来sort list,自然而然想到了merge sor... 阅读全文
摘要:
题目:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.F... 阅读全文
摘要:
leetcode很多题目都是利用快慢指针来解决题目,下面具体讲解下快慢指针。概念: 快指针在每一步走的步长要比慢指针一步走的步长要多。快指针通常的步速是慢指针的2倍。在循环中的指针移动通常为:faster = faster.next.next, slower = slower.next.应用:1.... 阅读全文
摘要:
题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题解:Merge k sorted linked list就是merge 2 sorted li... 阅读全文