当前位置:网站首页>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))
边栏推荐
- C4D quick start tutorial - creating models
- The wechat red envelope cover designed by the object is free! 16888
- CSAPP shell lab experiment report
- Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)
- ucore Lab 1 系统软件启动过程
- In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
- ucore lab1 系统软件启动过程 实验报告
- Sorting odd and even subscripts respectively for leetcode simple problem
- Report on the double computer experiment of scoring system based on 485 bus
- What if software testing is too busy to study?
猜你喜欢
随机推荐
软件测试有哪些常用的SQL语句?
How to become a good software tester? A secret that most people don't know
Thinking about three cups of tea
The minimum sum of the last four digits of the split digit of leetcode simple problem
ucorelab4
Jupyter installation and use tutorial
Unpleasant error typeerror: cannot perform 'ROR_‘ with a dtyped [float64] array and scalar of type [bool]
The maximum number of words in the sentence of leetcode simple question
MySQL数据库(四)事务和函数
Opencv recognition of face in image
[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)
ucore lab1 系统软件启动过程 实验报告
Word macro operation: convert the automatic number in the document into editable text type
[200 opencv routines] 98 Statistical sorting filter
Interface test interview questions and reference answers, easy to grasp the interviewer
Should wildcard import be avoided- Should wildcard import be avoided?
ucore lab6 调度器 实验报告
Threads and thread pools
Automated testing problems you must understand, boutique summary
The wechat red envelope cover designed by the object is free! 16888