题解 | #美妙的约会#

美妙的约会

http://www.nowcoder.com/practice/cc3eef5aed91489f9b706f4196e0d5c6

import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedList; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    ArrayList<Integer> arr = new ArrayList<>();
    String str = null;
    int n = Integer.parseInt(in.readLine());
    String[] s = in.readLine().split(" ");
       for(int i = 0;i < n*2; i++){
            arr.add(Integer.parseInt(s[i]));
        }
        int sum = 0;
        int i = 0;
        while(i < arr.size()){
             int j = arr.lastIndexOf(arr.get(i));
                sum = sum + j - i -1;
                arr.remove(j);
            i++;
        }
        
        System.out.println(sum);

}

}

全部评论

相关推荐

点赞 评论 收藏
分享
05-05 21:45
已编辑
广州大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务