本帖最后由 a9623a 于 2016-4-25 14:34 编辑
- package test;
- import java.util.ArrayList;
- public class Math {
- public static void main(String[] args) {
-
- System.out.println(getPerson(100));
- }
-
- public static int getPerson(int count) {
-
- ArrayList<Integer> as = new ArrayList<>(100);
- for (int i = 0;i < count;i++) {
- as.add(i + 1);
- }
- return getNumber(as, 0);
-
- }
-
- public static int getNumber(ArrayList<Integer> as,int numberEnd) {
- for (int i = 0;i < as.size();i++) {
- if ((as.get(i) + numberEnd) % 14 == 0) {
- as.remove(i);
- }
- }
-
- if (as.size() > 1) {
- numberEnd += as.get(as.size() - 1);
- getNumber(as,numberEnd);
- }
-
- return as.get(0);
- }
-
-
- }
复制代码
我也增加一种思路,使用递归.
|