码迷,mamicode.com
首页 > 其他好文 > 详细

Bloomberg面经准备: Josephus problem

时间:2016-12-17 07:35:23      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:art   tar   procedure   node   color   ble   single   from   ram   

Given a circular single linked list.Write a program that deletes every kth node until only one node is left. 
After kth node is deleted, start the procedure from (k+1)th node. 
e.g.list is 1->2->3->4->5->1 
k=3 
1. You are at 1, delete 3. 
List is: 1->2->4->5->1 
2. You are at 4, delete 1 
List is: 2->4->5->2 
3. You are at 2,delete 5 
List is: 2->4->2 
4. You are at 2, delete 2 
List is: 4 
Return 4. 

How efficient you can do it?

 

Bloomberg面经准备: Josephus problem

标签:art   tar   procedure   node   color   ble   single   from   ram   

原文地址:http://www.cnblogs.com/EdwardLiu/p/6189007.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!