Judge
1. 循环list中的所有元素然后删除重复
- public static List removeDuplicate(List list) {
- for ( int i = 0 ; i < list.size() - 1 ; i ++ ) {
- for ( int j = list.size() - 1 ; j > i; j -- ) {
- if (list.get(j).equals(list.get(i))) {
- list.remove(j);
- }
- }
- }
- return list;
- }
2. 通过HashSet踢除重复元素
- public static List removeDuplicate(List list) {
- HashSet h = new HashSet(list);
- list.clear();
- list.addAll(h);
- return list;
- }
在groovy中当然也可以使用上面的两种方法, 但groovy自己提供了unique方法来去除重复数据
- def list = [1, 2, 3, 2, 4, 1, 5]
- list.unique() // [1, 2, 3, 4, 5]
Judge的更多相关文章
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
- NOJ 1074 Hey Judge(DFS回溯)
Problem 1074: Hey Judge Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit interger IO format: ...
- 【教程】如何正确的写一个Lemon/Cena的SPJ(special judge)
转自:http://www.cnblogs.com/chouti/p/5752819.html Special Judge:当正确的输出结果不唯一的时候需要的自定义校验器 首先有个框架 #includ ...
- 九度 Online Judge 之《剑指 Offer》一书相关题目解答
前段时间准备华为机试,正好之前看了一遍<剑指 Offer>,就在九度 Online Judge 上刷了书中的题目,使用的语言为 C++:只有3题没做,其他的都做了. 正如 Linus To ...
- UVa Online Judge 工具網站
UVa Online Judge 工具網站 UVa中译题uHuntAlgorithmist Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 Mirror UVa Online Judg ...
- [swustoj 1021] Submissions of online judge
Submissions of online judge(1021) 问题描述 An online judge is a system to test programs in programming c ...
- HDOJ/HDU 1073 Online Judge(字符串处理~)
Problem Description Ignatius is building an Online Judge, now he has worked out all the problems exc ...
- write a macro to judge big endian or little endian
Big endian means the most significant byte stores first in memory. int a=0x01020304, if the cpu is b ...
- UVA 489-- Hangman Judge(暴力串处理)
Hangman Judge In ``Hangman Judge,'' you are to write a program that judges a series of Hangman gam ...
- 杭州电子科技大学Online Judge 之 “确定比赛名次(ID1285)”解题报告
杭州电子科技大学Online Judge 之 "确定比赛名次(ID1285)"解题报告 巧若拙(欢迎转载,但请注明出处:http://blog.csdn.net/qiaoruozh ...
随机推荐
- python函数--传参
一.位置参数 二.关键字参数 三.默认参数 四.任意数量的位置参数: 1. *x 2. 传入的多个参数,最终合并成一个元组 3. 之后的参数必须用关键字参数 五.任意数量的关键字参数 1. **x 2 ...
- Windows Embedded Compact 7新特性
Windows® Embedded Compact 7是Windows Embedded CE的下一代产品,而Windows Embedded CE这款操作系统面向占用资源少的新颖设备.Windows ...
- pyqt实践——从裸机到打包安装
1 安装python 安装python-2.7.6.msi默认在c盘 设置环境变量,path后追加c:/python27.可以在命令行直接认识命令python 2 安装pyqt PyQt4-4.10- ...
- OK335xS Qt network hacking
/********************************************************************** * OK335xS Qt network hacking ...
- Java [leetcode 25]Reverse Nodes in k-Group
题目描述: Given a linked list, reverse the nodes of a linked list k at a time and return its modified li ...
- C++学习笔记:指向函数的指针
#include <stdio.h> int sum(int a, int b) { return a+b; } int minus(int a, int b) { return a-b; ...
- SharePoint 2010 获取当前用户的权限
转:http://blog.csdn.net/sygwin_net/article/details/6790500 操作环境:SharePoint 2010 关于SharePoint 的权限架构,具体 ...
- android捕获ListView中每个item点击事件
转自:http://www.cnblogs.com/pswzone/archive/2012/03/10/2389275.html package com.wps.android; import ...
- 导出Excel帮助类
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.D ...
- HNU OJ10320 穿越火线 简单模拟
穿越火线 Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KB Total submit users: 12, A ...