Categorygithub.com/szhou12/leetcode-goleetcode0448-Find-All-Numbers-Disappeared-in-an-Array
package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev

# README

448. Find All Numbers Disappeared in an Array

Solution ideas

Simple idea - HashSet

用一个额外的array来模拟hashset

关联元素与index

把每一个元素看作一个index,然后把出现在这个元素作为index的位置上的元素 作标记为 $* -1$。 最后扫一遍所有元素,没有成为负数的元素,说明这个index没有出现过,故加入result中。

Time complexity = $O(n)$

Similar Problem

442. Find All Duplicates in an Array