CC150 LinkedList

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两种情况是不一样的。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值