算法面试题解答(八)

这一节我们来看看in-place类的问题。 什么叫in-place类问题呢?就是原地操作,也就等价于没有额外内存分配。

举例来说:

1. 有个句子,例如”This is a good book”,将单词顺序反转,变为如下的一个句子:“book good a is This”,要求in-place完成;

2. 有个单链表,链表的节点,除了next指针外,还有个random指针,指向链表中的某个元素或者NULL,要求复杂度是计算:O(n),Storage:O(1);

3. 有个字符串,将该字符串中出现的字符抽取出来;

当我们被问到一个问题的时候,我们往往假定输入的数据是不能做任何改变的,而事实往往不是这样的,有时面试官就是希望我们问出来,而不是做这样的假设。所以,“Do not make any assumption”!。

 

1. remove duplicate integers from an array

1. two loops, one loop is going through the whole list, the other loop is to check the element with other elements;

2. sorted the array;

3. merge-sort when doing the merge sort remove the duplicate.

 

 

Reference:http://tech-queries.blogspot.jp/2011/04/copy-linked-list-with-next-and-random.html

转载于:https://www.cnblogs.com/whyandinside/archive/2012/12/19/2825394.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值