CC150 LinkedList
2016-02-04 04:11
211 查看
CC150中的LinkedList讲的很好,之后上代码,最近太忙了
2.1 Write code to remove duplicates from an unsorted linked list.
这道题很简单就是利用HashTable存数然后遇到之前遇到过的节点直接删除
如果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.
Find a listNode to get the Kth last element from the linkedList,就是往后走k步,然后再开始走
也可以使用递归。如果当前节点的数字为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,
这道题使用了Stack,slow指针的位置对于奇数长度和偶数长度的LinkedList两种情况是不一样的。
2.1 Write code to remove duplicates from an unsorted linked list.
这道题很简单就是利用HashTable存数然后遇到之前遇到过的节点直接删除
如果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.
Find a listNode to get the Kth last element from the linkedList,就是往后走k步,然后再开始走
也可以使用递归。如果当前节点的数字为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,
这道题使用了Stack,slow指针的位置对于奇数长度和偶数长度的LinkedList两种情况是不一样的。
相关文章推荐
- ArcGIS 地图切图系列之(三)MapReduce 实现
- 例题10-9 UVA 1636 Headshot 决斗
- PTA乙级训练题1001-1012解答(C语言)
- TextView跑马灯效果
- Algorithm_Number of Digit One(1的数目)
- 数据结构(1)--线性表顺序表的主要操作的实现
- uva 542 France '98
- 【js】小数保留n位小数
- 204. Count Primes
- (一四五)第十三章编程练习
- (一四四)第十三章复习题
- (一四三)类设计回顾
- mongoose 文档(二)Models
- (一四二)继承和动态内存分配
- 我的2015羊年总结
- Android BLE学习(一): Android搜索BLE设备
- [2023]:求平均成绩
- HDU 1005 Number Sequence
- 高兴
- python threading模块使用 以及python多线程操作的实践(使用Queue队列模块)