1 Star 1 Fork 0

李明松/algorithm

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
HJ3.java 841 Bytes
一键复制 编辑 原始数据 按行查看 历史
msli 提交于 2021-10-11 17:04 +08:00 . update
package leetcode.huawei;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
/**
* @Description
* @Author msli
* @Date 2021/10/11
*/
public class HJ3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int n = in.nextInt();
int[] temp = new int[n];
for (int i = 0; i < n; i++) {
temp[i] = in.nextInt();
}
Arrays.sort(temp);
List<Integer> res = new ArrayList<>();
for (int i = 0; i < temp.length; i++) {
if (res.isEmpty() || res.get(res.size()-1) != temp[i]) {
res.add(temp[i]);
}
}
res.forEach(System.out::println);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/msli121/algorithm.git
git@gitee.com:msli121/algorithm.git
msli121
algorithm
algorithm
master

搜索帮助