package uniq

import "sort"

type Interface sort.Interface

func Ue(data Interface) int {
	len := data.Len()
	i, j := 0, 1
	// find the first duplicate
	for j < len && data.Less(i, j) {
		i++
		j++
	}
	// this loop is simpler after the first duplicate is found
	for ; j < len; j++ {
		if data.Less(i, j) {
			i++
			data.Swap(i, j)
		}
	}
	return i + 1
}

package uniq

import "sort"

type Interface sort.Interface

func Ue(data Interface) int {
	len := data.Len()
	if len == 0 {
		return 0
	}
	i, j := 0, 1
	// find the first duplicate
	for j < len && data.Less(i, j) {
		i++
		j++
	}
	// this loop is simpler after the first duplicate is found
	for ; j < len; j++ {
		if data.Less(i, j) {
			i++
			data.Swap(i, j)
		}
	}
	return i + 1
}

Fix Len() == 0 bug
Fix Len() == 0 bug
