[LeetCode]Missing Number
2015-09-24 15:14
141 查看
Given an array containing n distinct numbers taken from
find the one that is missing from the array.
For example,
Given nums =
Note:
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
参考了别人的代码
code:
0, 1, 2, ..., n,
find the one that is missing from the array.
For example,
Given nums =
[0, 1, 3]return
2.
Note:
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
参考了别人的代码
code:
public class Solution268 { public int missingNumber(int[] nums) { int sum=0; for(int i=0; i<=nums.length; i++){ sum+=i; } for(int i:nums) sum -=i; return sum; } }
相关文章推荐
- ios icon 尺寸
- sql语句中----删除表数据drop、truncate和delete的用法
- 用Swift开发二维码扫描器教程
- 深入了解Libgdx中间Skin分类
- 学习RMI
- Sublime用户如何快速高效开发跨平台App
- android系统中查看哪些端口被哪些应用打开
- 下载网页中的html5视频之手动方法
- 基本的Web控件二
- Spark SQL中的DataFrame
- Swift 中的指针使用
- 盘点 DevOps 世界的杰出女性(一)
- react-native试玩(35)-react-native-icons插件
- Partition List
- 网络请求的get,post 方法,同步,异步请求
- ksh 函数
- Swift控制流
- C# WebBrowser 一些方法
- 使用Eclipse构建Maven的SpringMVC项目
- 待攻城略地的任务