摘要: Sort a linked list using insertion sort. public ListNode InsertionSortList(ListNode head) { if(head == null || head.next == null) return head; ListNod 阅读全文
posted @ 2016-09-13 12:57 咖啡中不塌缩的方糖 阅读(109) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? 先用2 pointer查找到中间点,然后后半部分reverse, 最 阅读全文
posted @ 2016-09-13 11:52 咖啡中不塌缩的方糖 阅读(108) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up:Can you 阅读全文
posted @ 2016-09-13 11:43 咖啡中不塌缩的方糖 阅读(152) 评论(0) 推荐(0) 编辑
摘要: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy 阅读全文
posted @ 2016-09-13 11:13 咖啡中不塌缩的方糖 阅读(150) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, remove the nth node from the end of list and return its head. For example, Note:Given n will always be valid.Try to do this in on 阅读全文
posted @ 2016-09-13 10:35 咖啡中不塌缩的方糖 阅读(129) 评论(0) 推荐(0) 编辑
摘要: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin to in 阅读全文
posted @ 2016-09-13 09:49 咖啡中不塌缩的方糖 阅读(144) 评论(0) 推荐(0) 编辑
摘要: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 最简单的思路是利用之前Merge 2 sorted Lists, 逐个相加,但是这种的时间复杂度会更高 阅读全文
posted @ 2016-09-13 09:36 咖啡中不塌缩的方糖 阅读(119) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list in O(n log n) time using constant space complexity. O(n lg n) constant space的常见sort方法有 merge sort, quick sort, heap sort。 quick sor 阅读全文
posted @ 2016-09-13 09:20 咖啡中不塌缩的方糖 阅读(109) 评论(0) 推荐(0) 编辑
摘要: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 - 阅读全文
posted @ 2016-09-13 08:46 咖啡中不塌缩的方糖 阅读(80) 评论(0) 推荐(0) 编辑
摘要: Reverse a singly linked list. 解法: linked list 最典型的题型之一。 思路相同,也可以不用哨兵: 阅读全文
posted @ 2016-09-13 08:40 咖啡中不塌缩的方糖 阅读(104) 评论(0) 推荐(0) 编辑