一群人围成一圈报数,3倍数的就退出,面试题

    xiaoxiao2021-04-12  37

    这个题目指的是一群人,围成一个圈,然后一个接一个的报数,当数到3或者3的倍数时候就退出,知道最后一个人。

    距离当人数为30的时候:

    public class CycleTest {          public static void main(String[] args) {           // TODO Auto-generated method stub           cycle(30,3);       }          private static int cycle(int total, int k) {           List<Integer> dataList = new LinkedList<Integer>();           for (int i = 0; i < total; i++) {               dataList.add(new Integer(i+1));           }           int index = -1;           while (dataList.size()>1) {               index = (index + k)

    转载请注明原文地址: https://ju.6miu.com/read-667168.html

    最新回复(0)