搜狐畅游笔试题Java工程师
一个公司从一个试用期员工到N个月后,有多少员工
下面是我做的,如果有问题求赐教
import java.util.Scanner;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Queue;
public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); System.out.println(solve(n)); in.close(); } public static BigInteger solve(int n) { BigInteger m1 = BigInteger.valueOf(0); BigInteger m = BigInteger.valueOf(0); BigInteger yes = BigInteger.valueOf(1); Queue<BigInteger> queue = new LinkedList<BigInteger>(); if (n <= 3) { return BigInteger.valueOf(1); } while (queue.size() < 3) { queue.offer(m1); } while (n - 3 > 0) { --n; yes = yes.add(queue.poll()); queue.offer(yes); } while (!queue.isEmpty()) { m = m.add(queue.poll()); } return m.add(yes); }
}
#搜狐##Java工程师#
vivo公司福利 363人发布