当前位置:网站首页>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))边栏推荐
- Jupyter installation and use tutorial
- Iterators and generators
- Investment should be calm
- The number of reversing twice in leetcode simple question
- Word macro operation: convert the automatic number in the document into editable text type
- 基于485总线的评分系统双机实验报告
- Mysql database (IV) transactions and functions
- ucore lab1 系统软件启动过程 实验报告
- Thinking about three cups of tea
- How to become a good software tester? A secret that most people don't know
猜你喜欢

ucore lab5用户进程管理 实验报告

Take you to use wxpy to create your own chat robot (plus wechat interface basic data visualization)

如何成为一个好的软件测试员?绝大多数人都不知道的秘密
软件测试需求分析之什么是“试纸测试”

China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '

51 lines of code, self-made TX to MySQL software!

接口测试面试题及参考答案,轻松拿捏面试官
软件测试工作太忙没时间学习怎么办?
遇到程序员不修改bug时怎么办?我教你

MySQL数据库(四)事务和函数
随机推荐
ucore lab7 同步互斥 实验报告
CSAPP家庭作業答案7 8 9章
MySQL development - advanced query - take a good look at how it suits you
Pedestrian re identification (Reid) - Overview
51 lines of code, self-made TX to MySQL software!
Lab 8 文件系统
12306: mom, don't worry about me getting the ticket any more (1)
Jupyter installation and use tutorial
安全测试入门介绍
What if software testing is too busy to study?
Global and Chinese market of DVD recorders 2022-2028: Research Report on technology, participants, trends, market size and share
ucore lab2 物理内存管理 实验报告
Winter vacation daily question - maximum number of balloons
Which version of MySQL does php7 work best with?
What are the commonly used SQL statements in software testing?
Description of Vos storage space, bandwidth occupation and PPS requirements
Servlet
软件测试需求分析之什么是“试纸测试”
Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
Your wechat nickname may be betraying you