LeetCode Missing Number (简单题)
题意:
给一个含有n个整数的数组,数组中的元素应该是0~n。现在缺了其中某1个,找出缺少的那个整数?
思路:
0~n的总和是可以直接计算的,而缺少的那个就是sum减去数组的和。
int missingNumber(vector<int>& nums)
{
int sum=;
for(int i=; i<nums.size(); i++)
sum+=i+-nums[i];
return sum;
}
AC代码
LeetCode Missing Number (简单题)的更多相关文章
- HDU 5166 Missing number 简单数论
Missing number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) [ ...
- PAT 1144 The Missing Number[简单]
1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...
- [LeetCode] Missing Number 丢失的数字
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- [LeetCode] Missing Number (A New Questions Added Today)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- (leetcode)Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- LeetCode——Missing Number
Description: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one t ...
- 力扣485. 最大连续1的个数-C语言实现-简单题
题目 [题目传送门] 给定一个二进制数组, 计算其中最大连续1的个数. 示例 1: 输入: [1,1,0,1,1,1] 输出: 3 解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 3 ...
- PAT-1144(The Missing Number)set的使用,简单题
The Missing Number PAT-1144 #include<iostream> #include<cstring> #include<string> ...
- leetcode简单题6
今天的华师 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, fro ...
随机推荐
- hdu1076
#include<iostream> using namespace std; int main() { int cases; int k; cin>>cases; while ...
- jeecms v8 网站访问量配置
<script src="${resSys}/jquery.js" type="text/javascript"></script> & ...
- 【C#】截取字符串
几个经常用到的字符串的截取 string str="123abc456"; int i=3; 1 取字符串的前i个字符 str=str.Substring(0,i); // or ...
- 空字符串‘’ null false 区别
1.''空字符串 .null 和false都是以值为0来存储的 只是数据结构不一致而已 空字符串------字符串数据格式 null -----------null数据格式 false ----- ...
- nextSibling 和nextElementSibling
在使用DOM过程中发现一个问题: 使用nextSibling 属性返回指定节点之后紧跟的节点,在相同的树层级中.被返回的节点以 Node 对象返回. this.arrow = this.screen. ...
- Problem C: [noip2016十连测第五场]travel (构造+贪心)
题面 https://www.lydsy.com/JudgeOnline/upload/201610/statements(1).pdf 题解 好神仙的贪心-- 首先无解的情况很容易判断,就是\(l= ...
- PureComponent
前言 React15.3中新加了一个 PureComponent 类,PureComponent 也就是纯组件,取代其前身 PureRenderMixin , PureComponent 是优化 Re ...
- 洛谷P2746 校园网Network of Schools
题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作"接受学校").注意即使 \(B\) 在 \(A\) 学校的分发列表中, \(A ...
- PAT甲级——1096 Consecutive Factors (数学题)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors ...
- django--权限(1)初识
一.权限表结构设计 1.认识权限 生活中处处有权限,比如,腾讯视频开会员才有观看某个最新电影的权限,你有房间钥匙就有了进入这个房间的权限,等等.同样,程序开发过程中也有权限,我们今天说的权限指的是we ...