`
songlj
  • 浏览: 15972 次
社区版块
存档分类
最新评论

Missing Number

 
阅读更多

解题思路:利用输入漏掉数字的数组所有数字之和和完全数组之和,做减法,即差值即是所要的.

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/




版权声明:本文为博主原创文章,未经博主允许不得转载。

分享到:
评论

相关推荐

    FindMissingNumber

    目的 编写 Android 应用程序以查找范围中缺少的数字。 参考 结果 问题陈述 考虑一个连续范围的整数。 除了一个数字之外的所有数字都以任何顺序放入一个数组中。 示例 预期范围为 500 到 600(含)。...

    cpp-算法精粹

    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 ...

    LeetCode最全代码

    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 ...

    程序传输软件V13.0

    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 ...

    leetcode添加元素使和等于-LeetCode:力扣唱片

    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...

    matlabeof代码-utl_determining_the_missing_numbers_and_duplicates_in_a_lis

    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

    0到n-1缺失的数字1

    示例 1:输入: [0,1,3]输出: 2示例 2:输入: [0,1,2,3,4,5,6,7,9]输出: 8int missingNumber(vector&lt;i

    JAD解决MISSING_BLOCK_LABEL心得

    Currently Jad ignores the contents of the Line Number Table Attribute and the Source File Attribute(不明白什么意思) 5.JAD不能处理继承信息,总是把java.lang.Object作为两个不同类的通用父类,需要的时候...

    leetcode530-leetcode:力扣在线评委

    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:刷题心得

    刷leetcode不用stl CP-tricks 刷题心得 刷题技巧总结 string c++ STL: find_last_not_of, ...[Missing Number]: 找到0-n中缺失的数字。使用XOR来实现O(1)空间 : 使用二分。正确性比较难证明。 单调栈 注意在向前的

    圆和矩形是否重叠leetcode-leetcode_solutions:leetcode_solutions

    两个指针,前后,交换268.Missing Number -&gt; 数字之和 [0,1,2,...,n] 是一个常数,所以可以计算出缺失的那个169.Majority Element -&gt; Hashtable | Boyer-Moore 多数投票算法283. 移零 -&gt; 27. 移除元素243.Shortest ...

    leetcode338-algorithm-training:leetcodecjava

    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 + Puttygen + Putty

    这是全部OpenSSH的RPM包跟SSH终端Putty

    Number Zoo Patrol

    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

    QHierarchy 4.2 最新版Unity插件

    - 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 ...

    Seleniumwebdriver中的“缺少或无效的'entry.level'”错误

    我也遇到了“ google.com”相同的错误,经过这么多的努力,我才知道输入框的ID在chrome和firefox中是不同的。 我从chrome中选择了id,但是我正在chrome上执行脚本。 因此,请正确检查您的定位器,问题可能是...

    Foursquare数据集

    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...

    Bupa 数据集

    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

    Pro_CSharp_5.0_and_the_.NET_4.5_Framework_6th_edition

    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 ...

Global site tag (gtag.js) - Google Analytics