Problem Single Number II

Problem Description:

Given an array of integers, every element appears three times except for one. Find that single one.

Solution:

1          Arrays.sort(A);
2         for (int i = 2; i < A.length; i += 3) {
3             if (A[i] != A[i-2]) {
4                 return A[i-2];
5             }
6         }
7 
8         return A[A.length - 1];

 

posted @ 2014-06-29 14:38  HaruHaru  阅读(89)  评论(0编辑  收藏  举报