当前位置:网站首页>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);
}
}
边栏推荐
- 使用Electron开发桌面应用
- ssh免密登录设置及使用脚本进行ssh登录并执行指令
- Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
- 发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
- 质量体系建设之路的分分合合
- sync. Interpretation of mutex source code
- Acwing 4300. Two operations
- Programmers' experience of delivering takeout
- [depth first search] 695 Maximum area of the island
- 第六章 数据流建模—课后习题
猜你喜欢
远程升级怕截胡?详解FOTA安全升级
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
Solution to the palindrome string (Luogu p5041 haoi2009)
[to be continued] [UE4 notes] L3 import resources and project migration
Hang wait lock vs spin lock (where both are used)
2022年上半年国家教师资格证考试
Improvement of pointnet++
Bucket sort
Little known skills of Task Manager
[to be continued] [depth first search] 547 Number of provinces
随机推荐
[depth first search] 695 Maximum area of the island
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
[转]: OSGI规范 深入浅出
剑指 Offer 05. 替换空格
26、 File system API (device sharing between applications; directory and file API)
每日一题-无重复字符的最长子串
Detailed explanation of expression (csp-j 2021 expr) topic
Educational Codeforces Round 107 (Rated for Div. 2) E. Colorings and Dominoes
[trans]: spécification osgi
[turn to] MySQL operation practice (I): Keywords & functions
过拟合与正则化
National teacher qualification examination in the first half of 2022
二十六、文件系统API(设备在应用间的共享;目录和文件API)
[merge array] 88 merge two ordered arrays
Insert sort
object serialization
注解与反射
Binary search basis
Csp-j-2020-excellent split multiple solutions
After setting up the database and website When you open the app for testing, it shows that the server is being maintained