题解 | #序列找数#
序列找数
https://www.nowcoder.com/practice/a7d1856a72404ea69fdfb5786d65539c
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int i = 0; int max = in.nextInt(); int sum = 0; int tmp = 0; for (; in.hasNextInt(); i++) { tmp += in.nextInt(); } if (max != i){ System.out.println(i); return; } sum = ((1 + i) * i) / 2; System.out.println(sum - tmp); } }