打卡|Twitter|Find Missing Numbers in an Array

2021-01-18 IT信息教室
如果感覺本期內容還不錯,記得 關注收藏轉發分享 呀~

Given an array of integers of size n, where all elements are between 1 and n inclusive, find all of the elements of [1, n] that do not appear in the array. Some numbers may appear more than once.

給定一個有 n 的元素的正整數列表,列表中的元素是 1 到 n 的正整數,找到 [1, n] 區間中缺少的正整數,列表中可能出現相同的數值。

Test Case:

Input1: nums = [4, 6, 2, 6, 7, 2, 1]Output1:  [3, 5]

【下面是個廣告位】

參考代碼(Python 3):

class Solution:    def findDisappearedNumbers(self, nums):        for idx in range(len(nums)):            index = abs(nums[idx]) - 1            nums[index] = -abs(nums[index])        return [idx for idx, num in enumerate(nums, start = 1) if num > 0]    nums = [4, 6, 2, 6, 7, 2, 1]result = Solution().findDisappearedNumbers(nums)print(result)print(''.join(str(result).split()))

如果您對內容有什麼需求建議,或者遇到了什麼軟體、應用使用方面的問題,請直接在公眾號主界面下發私信給我,我看都會及時回復。感謝大家的支持!

合作: classroom.it@hotmail.com

Hi

你好呀

我是 M先森 

這是一個共同學習的平臺

我會把我會的 你們想學的

做成教程或者寫成文章
我們在這一起學英語 

學編程 學算法

學各種各樣

好玩的好用的軟體

記得要常回來看看呀

(^_^)a(^_^)a

點擊 閱讀原文 查看Python算法實戰系列~

喜歡就 分享 點讚 在看 三連吧!

Long-press QR code to transfer me a reward

As required by Apple's new policy, the Reward feature has been disabled on Weixin for iOS. You can still reward an Official Account by transferring money via QR code.

相關焦點

  • How ManyNumbers Are SmallerThan theCurrentNumber
    有多少小於當前數字的數字Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j !
  • 2019/10/25-LeetCode Array (Day01)
    Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.
  • look for, find與find out區別傻傻分不開!看完瞬間一清二楚!
    look for, find與find out區別傻傻分不開!看完瞬間一清二楚!Mom, I looked for the pet around the house, but I didn't find it. (look for指動作,find指結果)媽媽,我在房子周圍找了寵物,但是我沒有找到她。
  • Numpy學習打卡task01
    今天帶來的是Datawhale自主學習Numpy下學習打卡筆記第一部分—輸入輸出(為什麼沒有上,別問,問就是numpy.tan(90))。本文大致介紹了numpy的相關背景知識。本文素材來自網絡及datawhale,糾錯指正、深入探討,咱們評論區見。
  • Maximum Sum Circular Subarray 環形子數組的最大和
    Given a circular array C of integers represented by A, find the maximum
  • Excel函數總結二:VLOOKUP、LARGE、RANK、LEFT、MID和FIND
    table_array:查詢值所處的區域,使用對區域或區域名稱的引用,有時需要跨表格查找。col_index_num:返回第幾列內容,col_index_num為 1 時,返回 table_array 第一列的數值,col_index_num 為 2 時,返回table_array 第二列的數值,以此類推。
  • 《穿越火線》error missing fonts什麼意思 error missing fonts介紹
    導 讀在遊戲《穿越火線》中,error missing fonts的意思是遊戲字體報錯而無法進入遊戲。
  • Numbers|英語中的數字,一文打盡(雙語)
    In this article we shall take a look at how numbersare used in the English language.Most of the time using numbers is easy, but you should be aware of these other ways of expressing numbers in the English language!在本文中,我們將了解數字在英語中的使用方式。
  • Rotate Array
    This problem was recently asked by Facebook:Given an array and an integer k, rotate the array by k spaces. Do this without generating a new array and without using extra space.
  • Uniform Microstrip Array Antenna
    The an-tenna in [3] is 6×33 array of 1×6 subarray with series corporate feed network.Meanwhile in [4], the antenna is an 6×32 element array of 1×6 subarray with the output of each subarray connected through power combiner.
  • Search for missing Chinese woman in Missouri resumes
    Police have resumed the search for the body of a Chinese woman who has been missing in Missouri for a year.
  • find out與find與look for的區別
    一.find out意為「查明;弄清……(情況);發現」,多指通過調查、詢問和研究之後搞清楚、弄明白某事。例如:Can you find out when the sports meeting will be held?你能查清楚運動會什麼時候開始嗎?