public int singleNumberII(int[] A)
    {
        if(A == null || A.length % 3 == 0) return Integer.MAX_VALUE;
        if(A.length < 3) return A[0];
        sort(A);
        int j = 1;
        for(int i = 0; i<A.length-1;i++)
        {
          if(A[i] == A[i+1]) ++j;
            else {
              if(j < 3) return A[i];
              else if(j ==3) j=1;
              else return Integer.MAX_VALUE;
          }
        }
        if(j>3) return Integer.MAX_VALUE;
        return A[A.length-1];
    }