阅小文有一个长度为n的序列,他想移除掉里面的重复元素,对于每种元素保留最后出现的那个。

区块链毕设网qklbishe.com为您提供问题的解答

阅小文有一个长度为n的序列,他想移除掉里面的重复元素,对于每种元素保留最后出现的那个。  

import java.util.*; public class Main {     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         Set<Integer> set = new LinkedHashSet<>(); // 直接存         int n = in.nextInt();         for (int i = 0; i < n; i++) {             int x = in.nextInt();             if (set.contains(x)) {                 set.remove(x);             }             set.add(x);         }         int idx = 0;         for (int key : set) {             if (idx == set.size()-1) System.out.println(key);             else System.out.print(key + " ");             idx++;         }     } }

08:08

以上就是关于问题阅小文有一个长度为n的序列,他想移除掉里面的重复元素,对于每种元素保留最后出现的那个。的答案

欢迎关注区块链毕设网-
专业区块链毕业设计成品源码,定制。

区块链NFT链游项目方科学家脚本开发培训

承接区块链项目定制开发

微信:btc9767

QQ :1330797917

TELEGRAM: BTCOK9

承接区块链项目定制开发


qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 阅小文有一个长度为n的序列,他想移除掉里面的重复元素,对于每种元素保留最后出现的那个。