|
|
@@ -1,5 +1,27 @@
|
|
|
func findDisappearedNumbers(nums []int) (res []int) {
|
|
|
n := len(nums)
|
|
|
+ for i := 0; i < n; i++ {
|
|
|
+ if idx := abs(nums[i]) - 1; 0 < nums[idx] {
|
|
|
+ nums[idx] = -nums[idx]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for i := 0; i < n; i++ {
|
|
|
+ if 0 < nums[i] {
|
|
|
+ res = append(res, i+1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func abs(x int) int {
|
|
|
+ if x < 0 {
|
|
|
+ return -x
|
|
|
+ }
|
|
|
+ return x
|
|
|
+}
|
|
|
+
|
|
|
+func findDisappearedNumbersOn(nums []int) (res []int) { // O(n) extra space
|
|
|
+ n := len(nums)
|
|
|
set := make([]bool, n+1)
|
|
|
for _, i := range nums {
|
|
|
set[i] = true
|