题意:先将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 位运算的更多相关文章

  1. leetcode 268 Missing Number(异或运算的应用)

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  2. [LeetCode] 268. Missing Number ☆(丢失的数字)

    转载:http://www.cnblogs.com/grandyang/p/4756677.html Given an array containing n distinct numbers take ...

  3. Java [Leetcode 268]Missing Number

    题目描述: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...

  4. LeetCode 268. Missing Number (缺失的数字)

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

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

  6. [LeetCode] 268. Missing Number 缺失的数字

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  7. 33. leetcode 268. Missing Number

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

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

  9. &lt;LeetCode OJ&gt; 268. Missing Number

    268. Missing Number Total Accepted: 31740 Total Submissions: 83547 Difficulty: Medium Given an array ...

随机推荐

  1. mysql 存相同内容:utb8mb4 会比 utf8 占用更多的内存吗,utf8mb4 浪费内存吗?utf8 utf8mb4 区别

    原文:mysql 存相同内容:utb8mb4 会比 utf8 占用更多的内存吗,utf8mb4 浪费内存吗?utf8 utf8mb4 区别 参考:http://www.fengyunxiao.cn u ...

  2. Go语言实战_自己定义OrderedMap

    一. 自己定义OrderedMap 在Go语言中.字典类型的元素值的迭代顺序是不确定的.想要实现有固定顺序的Map就须要让自己定义的 OrderedMap 实现 sort.Interface 接口类型 ...

  3. Html表单使用实例

    原文 https://www.jianshu.com/p/b01f32844ac1 大纲 1.单选框多选框实现的商品选择 2.添加下拉框和删除下拉框 3.观察textarea中事件处理器的运行顺序 推 ...

  4. [ES7] Convert Any Function into an Asynchronous Function

    Any function can be made asynchronous, including function expressions, arrow functions, and methods. ...

  5. 常用有效检测数据库运行状态SQL脚本

    1.查看数据库中不为 InnoDB 引擎的表   SELECT TABLE_SCHEMA, TABLE_NAME, ENGINE   FROM information_schema.TABLES  W ...

  6. Android Error:(1,N1) 错误: 需要class, interface或enum

    造成这个error的原因是Java文件编码格式不对, 比如可能是你之前这个文件是用GBK写的,后来复制到utf-8环境里编译,而文件里有些是隐藏的字符,很难找出来的. 解决方法是在Notepad++新 ...

  7. Android 用LinkedList实现队列

    队列 队列是一种特殊的线性表,它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作.进行插入操作的端称为队尾,进行删除操作的端称为队头.队列中没有元素时,称为空队列. 在 ...

  8. SimpleDateFormat.format的简单使用小结

    format的用法 是将当前时间格式转换为指定格式 场景一:给定毫秒数或者当前系统时间,返回指定时间格式 输入         Date date=new Date();//获得系统当前的时间 //  ...

  9. [经典面试题]k节点一组旋转链表

    [题目] 给出一个链表和一个数k,比方链表1→2→3→4→5→6.k=2,则翻转后2→1→4→3→6→5,若k=3,翻转后3→2→1→6→5→4,若k=4.翻转后4→3→2→1→5→6. 假设节点的数 ...

  10. NSstring封装

    来自http://devtang.com/blog/2012/02/14/nsstring-java-like-wrapper/ NSStringWrapper.h #import <Found ...