class Utilities {

    public static int[] unique(int[] arr)
    {
        if (arr.length < 2)
        {
            return arr;
        }

        int lastDistinctIndex = 0;
        int lastId = arr[0];
        int[] distinctIds = new int[arr.length];
        distinctIds[0] = lastId;
        for (int index = 1; index < arr.length;)
        {
            int id = arr[index++];
            if (id != lastId)
            {
                lastId = id;
                distinctIds[++lastDistinctIndex] = id;
            }
        }

        if (lastDistinctIndex < distinctIds.length - 1)
        {
            distinctIds = Arrays.copyOf(distinctIds, lastDistinctIndex + 1);
        }

        return distinctIds;
    }

    private  Utilities();

}