解题思路:利用输入漏掉数字的数组所有数字之和和完全数组之和,做减法,即差值即是所要的.
Java代码实现:
public class Solution {
public int missingNumber(int[] nums) {
int sum1=0;
int sum=0;
for(int i=0;i<nums.length+1;i++)
sum1=sum1+i;
for(int i=0;i<nums.length;i++)
sum=sum+nums[i];
return sum1-sum;
}
}
原题地址:
https://leetcode.com/problems/missing-number/
版权声明:本文为博主原创文章,未经博主允许不得转载。
分享到:
相关推荐
目的 编写 Android 应用程序以查找范围中缺少的数字。 参考 结果 问题陈述 考虑一个连续范围的整数。 除了一个数字之外的所有数字都以任何顺序放入一个数组中。 示例 预期范围为 500 到 600(含)。...
Missing Number Maximum Product of Word Lengths Bitwise AND of Numbers Range Power of Three Rectangle Area 数论 Happy Number Ugly Number Ugly Number II Super Ugly Number Fraction to Recurring Decimal ...
268| [Missing Number](https://leetcode.com/problems/missing-number/) | [C++](./C++/missing-number.cpp) [Python](./Python/missing-number.py) | _O(n)_ | _O(1)_ | Medium | LintCode || 318| [Maximum ...
Version 11.0 It is a missing number. Version 10.0 (Nov.,2014) - Series 0i-MODEL F has been supported. Version 9.0 (June,2014) - License and specification has been changed. License The single ...
Missing Number 位图法。给定从 0 ~ n 之间选取的 n 个不同的数。要求找到其中的 missing number。 解释直接抄LeetCode评论区了 For people who don't understand this solution: what he's doing is he's using the...
matlab eof代码utl_determining_the_missing_...number and duplicates in a list of numbers Same result in WPS and SAS if you move the DOSUBL outside the datastep. I tried a HASH, see end of message Nic
示例 1:输入: [0,1,3]输出: 2示例 2:输入: [0,1,2,3,4,5,6,7,9]输出: 8int missingNumber(vector<i
Currently Jad ignores the contents of the Line Number Table Attribute and the Source File Attribute(不明白什么意思) 5.JAD不能处理继承信息,总是把java.lang.Object作为两个不同类的通用父类,需要的时候...
leetcode 530 力扣在线评委 # 问题 困难 解决方案 1 ...Missing Number 144. Binary Tree Preorder Traversal 2016.06.06 94. Binary Tree Inorder Traversal 318. Maximum Product of Word Length
刷leetcode不用stl CP-tricks 刷题心得 刷题技巧总结 string c++ STL: find_last_not_of, ...[Missing Number]: 找到0-n中缺失的数字。使用XOR来实现O(1)空间 : 使用二分。正确性比较难证明。 单调栈 注意在向前的
两个指针,前后,交换268.Missing Number -> 数字之和 [0,1,2,...,n] 是一个常数,所以可以计算出缺失的那个169.Majority Element -> Hashtable | Boyer-Moore 多数投票算法283. 移零 -> 27. 移除元素243.Shortest ...
Number/solution.c) 292 中等的 [✓](/src/292 Nim Game/solution.c) 111 简单的 [✓](/src/111 二叉树的最小深度/solution.c) 226 简单的 [✓](/src/226 反转二叉树/solution.c) 112 简单的 [✓](/src/112 路径和/...
可以根据你所需要的格式来进行转码 例如mp3格式等等
这是全部OpenSSH的RPM包跟SSH终端Putty
Number Zoo Patrol ...Zoo workers have no idea what number is missing, and are too incompetent to figure it out, so they’re hiring you to do it for them. In case the zoo loses another number, they wan
- Displaying the error icon (MonoBehaviour script missing / Reference property is null / String property is empty / Callback of event is missing) - Displaying icons of all scripts that attached to a ...
我也遇到了“ google.com”相同的错误,经过这么多的努力,我才知道输入框的ID在chrome和firefox中是不同的。 我从chrome中选择了id,但是我正在chrome上执行脚本。 因此,请正确检查您的定位器,问题可能是...
Missing Values? no Source: N/A Data Set Information: 2 files are included: 1. nodes.csv -- it's the file of all the users. This file works as a dictionary of all the users in this data set. It...
1. Title: BUPA liver disorders 2. Source information: -- Creators: BUPA Medical Research Ltd. -- Donor: Richard S.... 8 Grosvenor Avenue Mapperley Park Nottingham NG3 5DX ...8. Missing values: none
The book has actually shrunk in number of pages and although it has exactly the same number of chapters they are now arranged in eight sections rather than the previous seven. Let's account for the ...