摘要: 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)
摘要: Palindrome Linked List:Given a singly linked list, determine if it is a palindrome. 题意:判断给定的一个链表中数,是否为回文。 思路:参考http://www.bkjia.com/ASPjc/1031678.html中的解法,采用递归的方式进行判断。 代码: private ListNode lst; ... 阅读全文
posted @ 2016-01-14 19:39 Lewisr 阅读(127) 评论(0) 推荐(0)
摘要: Intersection of Two Linked Lists:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the followi... 阅读全文
posted @ 2016-01-14 19:26 Lewisr 阅读(141) 评论(0) 推荐(0)
摘要: Remove Linked List Elements: Remove all elements from a linked list of integers that have value val. Example: Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 –> 5 题意:... 阅读全文
posted @ 2016-01-14 19:16 Lewisr 阅读(111) 评论(0) 推荐(0)
摘要: Remove Nth Node From End of List:Given a linked list, remove the nth node from the end of list and return its head.For example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second n... 阅读全文
posted @ 2016-01-13 19:16 Lewisr 阅读(91) 评论(0) 推荐(0)
摘要: Delete Node in a Linked List: 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 -> 4 and you are given... 阅读全文
posted @ 2016-01-13 18:59 Lewisr 阅读(118) 评论(0) 推荐(0)