Medium 268题 Missing Number
来源:互联网 发布:java高级程序员 编辑:程序博客网 时间:2024/05/26 19:14
Question:
Given an array containing n distinct numbers taken from 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?
Solution: I have line of thinking almost immediately~just like the code below!
public class Solution { public int missingNumber(int[] nums) { int len=nums.length; int sum=(0+nums.length+1)*nums.length/2;//The SUM of the all number should be int res_sum=0; for(int i=0;i<=nums.length-1;i++) res_sum+=nums[i]; return sum-res_sum; }}
0 0
- Medium 268题 Missing Number
- 【LeetCode】(268)Missing Number(Medium)
- LeetCode #268 - Missing Number - Medium
- 268. Missing Number #Medium
- 268. Missing Number 难度:medium
- 【Leet Code】268. Missing Number---Medium
- Leetcode 268. Missing Number (Medium) (cpp)
- Leet Code OJ 268. Missing Number [Difficulty: Medium]
- Leetcode 第268题Missing Number
- 【LeetCode】268 Missing Number
- [268]Missing Number
- [268] Missing Number
- LeetCode(268)Missing Number
- [leetcode 268]Missing Number
- leetcode 268: Missing Number
- Leetcode #268 Missing Number
- [LeetCode 268] Missing Number
- leetcode 268 Missing Number
- 1056. 组合数的和(15)
- ios 网络监测
- jsp网页出现“Cannot return from outside a function or method”
- 【解题报告】Codeforces Round #371 (Div. 2)
- Android使用AsyncTask异步请求网络
- Medium 268题 Missing Number
- Javascript数组完全随机排列(数组乱序)
- Login with Vimeo in iOS App using oAuth tutorial
- vmware ubantu忘记密码
- LeetCode.Problem 5 Longest Palindromic Substring
- android6.0源码分析之Camera API2.0简介
- android6.0源码分析之Camera2 HAL分析
- CentOS7 从零开始搭建 Hadoop2.7集群
- Python 进阶_生成器 & 生成器表达式