当前位置:网站首页>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))
边栏推荐
- Lab 8 file system
- Scoring system based on 485 bus
- Mysql database (I)
- Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
- 基于485总线的评分系统
- ucore lab2 物理内存管理 实验报告
- Interview answering skills for software testing
- UCORE lab5 user process management experiment report
- How to become a good software tester? A secret that most people don't know
- Global and Chinese markets of MPV ACC ECU 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
CSAPP家庭作业答案7 8 9章
Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
What to do when programmers don't modify bugs? I teach you
Install and run tensorflow object detection API video object recognition system of Google open source
CSAPP家庭作業答案7 8 9章
Leetcode simple question: check whether two strings are almost equal
Mysql database (IV) transactions and functions
How to write the bug report of software test?
UCORE lab1 system software startup process experimental report
ucore lab7
随机推荐
Unpleasant error typeerror: cannot perform 'ROR_‘ with a dtyped [float64] array and scalar of type [bool]
Interview answering skills for software testing
安全测试入门介绍
The wechat red envelope cover designed by the object is free! 16888
C4D quick start tutorial - Introduction to software interface
Mysql database (I)
Intensive learning notes: Sutton book Chapter III exercise explanation (ex17~ex29)
Lab 8 文件系统
Jupyter installation and use tutorial
Investment operation steps
软件测试工作太忙没时间学习怎么办?
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
想跳槽?面试软件测试需要掌握的7个技能你知道吗
What are the software testing methods? Show you something different
The most detailed postman interface test tutorial in the whole network. An article meets your needs
Future trend and planning of software testing industry
UCORE lab5 user process management experiment report
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
Report on the double computer experiment of scoring system based on 485 bus
Leetcode simple question: check whether the numbers in the sentence are increasing