当前位置:网站首页>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);
}
}
边栏推荐
- Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
- Romance of programmers on Valentine's Day
- Double pointer Foundation
- 质量体系建设之路的分分合合
- SAP method of modifying system table data
- lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
- Talking about JVM (frequent interview)
- To be continued] [UE4 notes] L4 object editing
- Under the national teacher qualification certificate in the first half of 2022
- 剑指 Offer 06.从头到尾打印链表
猜你喜欢
![[turn to] MySQL operation practice (I): Keywords & functions](/img/b1/8b843014f365b786e310718f669043.png)
[turn to] MySQL operation practice (I): Keywords & functions

剑指 Offer 04. 二维数组中的查找

剑指 Offer 09. 用两个栈实现队列

剑指 Offer 53 - II. 0~n-1中缺失的数字

Merge sort

Yolov5 adds attention mechanism

Palindrome (csp-s-2021-palin) solution
![[to be continued] [depth first search] 547 Number of provinces](/img/c4/b4ee3d936776dafc15ac275d2059cd.jpg)
[to be continued] [depth first search] 547 Number of provinces

Romance of programmers on Valentine's Day

On-off and on-off of quality system construction
随机推荐
Time complexity and space complexity
Under the national teacher qualification certificate in the first half of 2022
Haut OJ 1241: League activities of class XXX
Haut OJ 1243: simple mathematical problems
Shell Sort
【Jailhouse 文章】Look Mum, no VM Exits
Solon 框架如何方便获取每个请求的响应时间?
Haut OJ 1218: maximum continuous sub segment sum
Haut OJ 1352: string of choice
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
每日一题-搜索二维矩阵ps二维数组的查找
Talking about JVM (frequent interview)
对象的序列化
Merge sort
PC寄存器
Haut OJ 1350: choice sends candy
常见的最优化方法
Maximum number of "balloons"
SAP-修改系统表数据的方法
Warning using room database: schema export directory is not provided to the annotation processor so we cannot export