当前位置:网站首页>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))边栏推荐
- How to build a nail robot that can automatically reply
- MySQL数据库(四)事务和函数
- 软件测试面试回答技巧
- C4D quick start tutorial - creating models
- STC-B学习板蜂鸣器播放音乐
- Stc-b learning board buzzer plays music
- Visual analysis of data related to crawling cat's eye essays "sadness flows upstream into a river" | the most moving film of Guo Jingming's five years
- Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
- 接口测试面试题及参考答案,轻松拿捏面试官
- Servlet
猜你喜欢

CSAPP家庭作业答案7 8 9章

ucore lab2 物理内存管理 实验报告

Sorting odd and even subscripts respectively for leetcode simple problem

C4D quick start tutorial - creating models

How to build a nail robot that can automatically reply

Rearrange spaces between words in leetcode simple questions

CSAPP家庭作業答案7 8 9章

线程及线程池

ucore lab 6

Portapack application development tutorial (XVII) nRF24L01 launch B
随机推荐
Thinking about three cups of tea
遇到程序员不修改bug时怎么办?我教你
Word macro operation: convert the automatic number in the document into editable text type
The minimum number of operations to convert strings in leetcode simple problem
Global and Chinese markets for GaN on diamond semiconductor substrates 2022-2028: Research Report on technology, participants, trends, market size and share
Interface test interview questions and reference answers, easy to grasp the interviewer
How to build a nail robot that can automatically reply
If the position is absolute, touchablehighlight cannot be clicked - touchablehighlight not clickable if position absolute
Servlet
Global and Chinese markets of Iam security services 2022-2028: Research Report on technology, participants, trends, market size and share
Maximum nesting depth of parentheses in leetcode simple questions
Crawler series (9): item+pipeline data storage
ucore lab 2
想跳槽?面试软件测试需要掌握的7个技能你知道吗
Jupyter installation and use tutorial
The most detailed postman interface test tutorial in the whole network. An article meets your needs
UCORE LaB6 scheduler experiment report
Unpleasant error typeerror: cannot perform 'ROR_‘ with a dtyped [float64] array and scalar of type [bool]
全网最详细的postman接口测试教程,一篇文章满足你
ucore lab6 调度器 实验报告