摘要: Remove Duplicates from Sorted List II:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given 1->2->3->3->4->4... 阅读全文
posted @ 2016-01-15 21:30 Lewisr 阅读(182) 评论(0) 推荐(0)
摘要: Insertion Sort List:Sort a linked list using insertion sort. 题意:使用插入排序的方式对链表进行排序。 思路:根据插入排序的思路,进行插入操作。 代码: public ListNode insertionSortList(ListNode head) { if(head==null||head.next==null) re... 阅读全文
posted @ 2016-01-15 21:21 Lewisr 阅读(147) 评论(0) 推荐(0)
摘要: Linked List Cycle: Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 题意:判断一个链表中是否存在环。 思路:(参考别人的做法)采用“快慢指针”检查链表是否含有环。即让一个指针一次走一步,另一个指针一次走两步,... 阅读全文
posted @ 2016-01-15 21:14 Lewisr 阅读(131) 评论(0) 推荐(0)
摘要: Swap Nodes in Pairs:Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only const... 阅读全文
posted @ 2016-01-15 21:06 Lewisr 阅读(137) 评论(0) 推荐(0)
摘要: Add Two Numbers:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ret... 阅读全文
posted @ 2016-01-15 21:01 Lewisr 阅读(107) 评论(0) 推荐(0)
摘要: Remove Duplicates from Sorted List: Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->... 阅读全文
posted @ 2016-01-15 20:55 Lewisr 阅读(116) 评论(0) 推荐(0)
摘要: Merge Two Sorted Lists: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 题意:合并两个有序的链表,并返回新的链表。 思路:使用双指针,分别指... 阅读全文
posted @ 2016-01-15 20:48 Lewisr 阅读(129) 评论(0) 推荐(0)