首页 > 代码库 > Problem Single Number II

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];