当前位置:网站首页>LeetCode#268. Missing numbers
LeetCode#268. Missing numbers
2022-07-06 15:22:00 【Rufeng ZHHH】
subject :
Given an inclusion [0, n] in n Array of Numbers nums , find [0, n] The number that doesn't appear in the array in this range .
Example 1:
Input :nums = [3,0,1]
Output :2
explain :n = 3, Because there is 3 A digital , So all the numbers are in range [0,3] Inside .2 It's the missing number , Because it didn't show up in nums in .
Example 2:
Input :nums = [0,1]
Output :2
explain :n = 2, Because there is 2 A digital , So all the numbers are in range [0,2] Inside .2 It's the missing number , Because it didn't show up in nums in .
Example 3:
Input :nums = [9,6,4,2,3,5,7,0,1]
Output :8
explain :n = 9, Because there is 9 A digital , So all the numbers are in range [0,9] Inside .8 It's the missing number , Because it didn't show up in nums in .
Example 4:
Input :nums = [0]
Output :1
explain :n = 1, Because there is 1 A digital , So all the numbers are in range [0,1] Inside .1 It's the missing number , Because it didn't show up in nums in .
Tips :
n == nums.length
1 <= n <= 104
0 <= nums[i] <= n
nums All the numbers in are unique
source : Power button (LeetCode)
link : Power button
We can solve this problem by using the relevant knowledge of the arithmetic sequence , Relatively simple .
class Solution:
def missingNumber(self, nums: List[int]) -> int:
return int(len(nums)*(len(nums)+1)/2-sum(nums))
边栏推荐
- JDBC introduction
- Description of Vos storage space, bandwidth occupation and PPS requirements
- Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
- Install and run tensorflow object detection API video object recognition system of Google open source
- 想跳槽?面试软件测试需要掌握的7个技能你知道吗
- Do you know the advantages and disadvantages of several open source automated testing frameworks?
- Opencv recognition of face in image
- 软件测试Bug报告怎么写?
- Mysql database (II) DML data operation statements and basic DQL statements
- Preface to the foundations of Hilbert geometry
猜你喜欢
Scoring system based on 485 bus
Jupyter installation and use tutorial
Interview answering skills for software testing
Threads et pools de threads
Crawler series (9): item+pipeline data storage
Sleep quality today 81 points
Video scrolling subtitle addition, easy to make with this technique
UCORE lab5 user process management experiment report
Do you know the performance testing terms to be asked in the software testing interview?
The most detailed postman interface test tutorial in the whole network. An article meets your needs
随机推荐
Leetcode notes - dynamic planning -day6
pytest
MySQL数据库(四)事务和函数
Capitalize the title of leetcode simple question
ucore lab8 文件系统 实验报告
Should wildcard import be avoided- Should wildcard import be avoided?
遇到程序员不修改bug时怎么办?我教你
基于485总线的评分系统双机实验报告
Knowledge that you need to know when changing to software testing
Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
Interview answering skills for software testing
自动化测试你必须要弄懂的问题,精品总结
Preface to the foundations of Hilbert geometry
Description of Vos storage space, bandwidth occupation and PPS requirements
Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
Intensive learning notes: Sutton book Chapter III exercise explanation (ex17~ex29)
Future trend and planning of software testing industry
Rearrange spaces between words in leetcode simple questions
CSAPP家庭作業答案7 8 9章
UCORE lab7 synchronous mutual exclusion experiment report