CC150中的LinkedList讲的很好,之后上代码,最近太忙了
2.1 Write code to remove duplicates from an unsorted linked list.
如果No buffer used,就是只能使用O(1) space complexity, you can not extral space. 就是二维的遍历,从一个节点开始遍历之后所有的节点,如果有后面的节点和当前的节点相同就删除后面的节点。
2.2 Implement an algorithm to find the kth to last element of a singly linked list.
也可以使用递归。如果当前节点的数字为k + 1, 就删除之后的节点
2.3 Implement an algorithm to delete a node in the middle of a singly linked list, givenonly access to that node.
这道题是你只有Access 到你想删除的元素,所以就找到那个你想删除的元素,然后把next的value赋值,然后删除next就好
2.4Write code to partition a linked list around a value x, such that all nodes less than xcome before alt nodes greater than or equal to x.
2.5You have two numbers represented by a linked list, where each node contains asingledigit.Thedigitsarestoredinreverseorder,suchthatthe 1'sdigitisat theheadof the list. Write a function that adds the two numbers and returns the sum as alinked list.
这道题可以写成递归的形式,就会转换成找到最后一个元素然后计算
2.6 Given a circular linked list, implement an algorithm which returns the node at thebeginning of the loop. 利用快慢指针,有一定的技巧性
2.7 Implement a function to check if a linked list is a palindrome,