美文网首页
Go 数组去重 []int64

Go 数组去重 []int64

作者: jiangadam | 来源:发表于2018-03-20 11:43 被阅读44次

uids 里去除重复的uid,思路其实都差不多

func RemoveRepeatUid(uids []int64) []int64 {
    tempUids := []int64{}
    for _, i := range uids {
        if len(tempUids) == 0 {
            tempUids = append(tempUids, i)
        } else {
            for k, v := range tempUids {
                if i == v {
                    break
                }
                if k == len(tempUids)-1 {
                    tempUids = append(tempUids, i)
                }
            }
        }
    }
    return tempUids
}

相关文章

网友评论

      本文标题:Go 数组去重 []int64

      本文链接:https://www.haomeiwen.com/subject/fyivqftx.html