注册账号 登录
小春网 返回首页

tree77heaven的个人空间 https://www.incnjp.com/?294237 [收藏] [复制] [分享] [RSS]

日志

codility 1

已有 272 次阅读2017-3-13 17:17 |个人分类:codility|系统分类:学习

import java.util.ArrayList;
import java.util.Collections;

// you can also use imports, for example:
// import java.util.*;

// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");



class Solution {

public static void main(String[] args){

int A[]={22,22,22,411,411, 333,333,4,4,4, 4,1555, 1555,1555,1555};



int i=0;

int count=0;

   int ret=-1000;
  ArrayList List = new ArrayList();



   for(i=0;i<A.length;i++){
    List.add(A[i]);
   }



   Collections.sort(List);

   System.out.println(List.toString());


int tempi=Integer.parseInt(List.get(0).toString()) ;

   for(i=0;i<List.size();i++){
    if (tempi==Integer.parseInt(List.get(i).toString())) {
    count=count+1;
    }
    if (tempi!=Integer.parseInt(List.get(i).toString())) {
    if (count % 2 ==1){
    ret=tempi;
    break;
    }
    count=1;
    tempi=Integer.parseInt(List.get(i).toString());
    }
   }

   if (ret==-1000){
    ret=tempi;
   }



 System.out.println(ret);

}

}

悲剧

无聊

震惊

支持

不解

超赞

愤怒

高兴

全部作者的其他最新日志

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册账号

小春网
常务客服微信
微信订阅号
手机客户端
扫一扫,查看更方便! 返回顶部