Skip to content

LCR 120.寻找文件副本

md
设备中存有 n 个文件,文件 id 记于数组 documents。若文件 id 相同,则定义为该文件存在副本。请返回任一存在副本的文件 id。

示例 1:

输入:documents = [2, 5, 3, 0, 5, 0]
输出:0 或 5
 
提示:

0 ≤ documents[i] ≤ n-1
2 <= n <= 100000
go
func findRepeatDocument(documents []int) int {
	m := make(map[int]int)
	res := 0
	for _, v := range documents {
		m[v]++
		if m[v] > 1 {
			res = v
		}
	}
	return res
}
本站访客数 人次 本站总访问量