当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢
![[trans]: spécification osgi](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[trans]: spécification osgi

SAP-修改系统表数据的方法

YOLOv5添加注意力機制

Gbase database helps the development of digital finance in the Bay Area
![[to be continued] [UE4 notes] L2 interface introduction](/img/0f/268c852b691bd7459785537f201a41.jpg)
[to be continued] [UE4 notes] L2 interface introduction
![[merge array] 88 merge two ordered arrays](/img/e9/a73d9f22eead8e68c1e45c27ff6e6c.jpg)
[merge array] 88 merge two ordered arrays
![[轉]: OSGI規範 深入淺出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[轉]: OSGI規範 深入淺出
![[to be continued] [UE4 notes] L3 import resources and project migration](/img/81/6f75f8fbe60e037b45db2037d87bcf.jpg)
[to be continued] [UE4 notes] L3 import resources and project migration

Count sort

Chapter 6 data flow modeling - after class exercises
随机推荐
[merge array] 88 merge two ordered arrays
剑指 Offer 05. 替换空格
object serialization
What is the agile proportion of PMP Exam? Dispel doubts
[转]: OSGI规范 深入浅出
[depth first search] 695 Maximum area of the island
How can the Solon framework easily obtain the response time of each request?
Haut OJ 1241: League activities of class XXX
High precision subtraction
剑指 Offer 09. 用两个栈实现队列
[to be continued] [UE4 notes] L2 interface introduction
Download xftp7 and xshell7 (official website)
Solon Logging 插件的添加器级别控制和日志器的级别控制
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
Web APIs DOM节点
Hang wait lock vs spin lock (where both are used)
Pointnet++的改进
ssh免密登录设置及使用脚本进行ssh登录并执行指令
Developing desktop applications with electron
使用Electron开发桌面应用