Leetcode 268 Missing Number 位运算
题意:先将0, 1, 2, ..., n放入数组,然后去掉其中一个值,找到那个值。
这题与singe number 是一个类型,变形的地方就是首先需要将0, 1, 2, ..., n再次放入这个数组,这样就和singe number 一样。
class Solution {
public:
int missingNumber(std::vector<int>& nums) {
int ans = ;
for (std::vector<int>::size_type i = ; i < nums.size(); ++i){
ans ^= nums[i];
}
for (int i = ; i <= nums.size(); ++i){
ans ^= i;
}
return ans;
}
};
Leetcode 268 Missing Number 位运算的更多相关文章
- leetcode 268 Missing Number(异或运算的应用)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- [LeetCode] 268. Missing Number ☆(丢失的数字)
转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...
- Java [Leetcode 268]Missing Number
题目描述: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...
- LeetCode 268. Missing Number (缺失的数字)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- LeetCode 268. Missing Number缺失数字 (C++/Java)
题目: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is mi ...
- [LeetCode] 268. Missing Number 缺失的数字
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- 33. leetcode 268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- LeetCode - 268. Missing Number - stable_sort应用实例 - ( C++ ) - 解题报告
1.题目大意 Given an array nums, write a function to move all 0's to the end of it while maintaining the ...
- <LeetCode OJ> 268. Missing Number
268. Missing Number Total Accepted: 31740 Total Submissions: 83547 Difficulty: Medium Given an array ...
随机推荐
- ng build --base-href的设定问题
项目构建部署中遇到的问题: 1.不使用hash,如何解决刷新页面404的问题? 说明: root 指定项目地址路径,默认为nginx下的html index 默认访问index文件 try_fil ...
- 问题:CListCtrl如何高亮选中一行 http://zhidao.baidu.com/question/100664911.html 扩展:单行、双行及完成状态的字体等等。。。
http://zhidao.baidu.com/link?url=BKp05mfOdKbEBh21svQelpVhYjzDkIpYUZay8_3ZLSndTQn5kK0eTwQG8jBvYnwh8US ...
- windows关闭进程 批处理端口占用
cmd 关闭进程java taskkill /F /IM java.exe taskkill /f /im java.exe 如何用dat批处理文件关闭某端口对应程序-Windows自动化命令 如何用 ...
- [Swift] Storyboard outlet and action
To programmaictlly change the content of app, we need to contect storyboard to a view controller. To ...
- acdream 1430 SETI 后缀数组+height分组
这题昨天比赛的时候逗了,后缀想不出来,由于n^2的T了,就没往后缀数组想--并且之后解题的人又说用二分套二分来做.然后就更不会了-- 刚才看了题解,唉--原来题讲解n^2的也能够过,然后就--这样了! ...
- UUIDUtils工具类
原理是根据自身的操作系统和电脑硬件生成的一个32位的随机字符串,如果是一台电脑使用的话,一年不会重复,经过java之后貌似编程了36位,多了4个"-",下面是代码实现: impor ...
- scss 常用语法
点击查看 sass 官方文档 1.编译 初学可以在atom 中编译 安装命令 gem install sass atom中安装atom-sass ,mac 中"control+option+ ...
- Scrapy系列教程(1)------命令行工具
默认的Scrapy项目结构 在開始对命令行工具以及子命令的探索前,让我们首先了解一下Scrapy的项目的文件夹结构. 尽管能够被改动,但全部的Scrapy项目默认有类似于下边的文件结构: scrapy ...
- 【codeforces 750A】New Year and Hurry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- iOS9.0 生成证书流程一(非推送)
1.首先进入网址 http://developer.apple.com 2.第二登入,点击