日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

448. Find All Numbers Disappeared in an Array

發(fā)布時(shí)間:2023/12/20 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 448. Find All Numbers Disappeared in an Array 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Given an array of integers where 1 ≤ a[i] ≤?n?(n?= size of array), some elements appear twice and others appear once.

Find all the elements of [1,?n] inclusive that do not appear in this array.

Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

Example:

Input: [4,3,2,7,8,2,3,1]Output: [5,6]

給出n個(gè)數(shù),其中1~n中有些數(shù)沒(méi)出現(xiàn),求這些沒(méi)出現(xiàn)的數(shù)。

我們可以將數(shù)值和數(shù)組的標(biāo)關(guān)聯(lián),運(yùn)用負(fù)號(hào)巧妙的解決了這個(gè)問(wèn)題。確保每個(gè)出現(xiàn)過(guò)的數(shù)都變成負(fù)數(shù)

class Solution { public:vector<int> findDisappearedNumbers(vector<int>& nums) {vector<int> v;for (int i = 0; i < nums.size(); ++i) {int index = abs(nums[i]) - 1;nums[index] = -abs(nums[index]);}for (int i = 0; i < nums.size(); ++i) {if (nums[i] > 0) v.push_back(i + 1);}return v;} };

?

轉(zhuǎn)載于:https://www.cnblogs.com/pk28/p/7250740.html

總結(jié)

以上是生活随笔為你收集整理的448. Find All Numbers Disappeared in an Array的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。