当前位置:网站首页>Sword finger offer 53 - ii Missing numbers from 0 to n-1
Sword finger offer 53 - ii Missing numbers from 0 to n-1
2022-07-05 05:29:00 【ThE wAlkIng D】
Title Description
)
Problem analysis
Use the formula of arithmetic sequence to find n Xiang He , Then find the sum of the array , Subtract the two
Code instance
class Solution {
public int missingNumber(int[] nums) {
int n = nums.length;
int a = n * (n + 1) / 2;
int sum = 0;
for(int i = 0;i < nums.length;i++){
sum += nums[i];
}
return (a - sum);
}
}
边栏推荐
- [allocation problem] 135 Distribute candy
- [to be continued] [depth first search] 547 Number of provinces
- [to be continued] [UE4 notes] L3 import resources and project migration
- [es practice] use the native realm security mode on es
- Using HashMap to realize simple cache
- To be continued] [UE4 notes] L4 object editing
- 【ES实战】ES上的native realm安全方式使用
- Under the national teacher qualification certificate in the first half of 2022
- MySQL数据库(一)
- 一个新的微型ORM开源框架
猜你喜欢
Solution to the palindrome string (Luogu p5041 haoi2009)
To the distance we have been looking for -- film review of "flying house journey"
剑指 Offer 53 - II. 0~n-1中缺失的数字
sync.Mutex源码解读
Service fusing hystrix
Reader writer model
Web APIs DOM node
远程升级怕截胡?详解FOTA安全升级
C language Essay 1
Chapter 6 data flow modeling - after class exercises
随机推荐
Gbase database helps the development of digital finance in the Bay Area
剑指 Offer 35.复杂链表的复制
Pointnet++ learning
Use of room database
[turn to] MySQL operation practice (I): Keywords & functions
Insert sort
Demonstration of using Solon auth authentication framework (simpler authentication framework)
The number of enclaves
Maximum number of "balloons"
[to be continued] [UE4 notes] L1 create and configure items
Summary of Haut OJ 2021 freshman week
Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
kubeadm系列-00-overview
High precision subtraction
Time complexity and space complexity
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
【Jailhouse 文章】Look Mum, no VM Exits
[speed pointer] 142 circular linked list II
Chapter 6 data flow modeling - after class exercises
GBase数据库助力湾区数字金融发展