题解 | #序列中删除指定数字#
序列中删除指定数字
https://www.nowcoder.com/practice/7bbcdd2177a445a9b66da79512b32dd7
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
// int[] 的长度是不可变的,要能够删除的话得用集合的方式
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
ArrayList<Integer> array = new ArrayList<Integer>();
for (int i = 0; i < a; i++) {
array.add(in.nextInt());
}
int b = in.nextInt();
for (int y = 0; y < array.size(); y++) {
if (array.get(y) == b) {
array.remove(y);
y = y - 1;
}
}
for (int x = 0; x < array.size(); x++) {
System.out.print(array.get(x) + " ");
}
}
}
}
顺丰集团工作强度 303人发布