题意:先将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. html中radio、checkbox选中状态研究(静下心来看,静下心来总结)

    html中radio.checkbox选中状态研究(静下心来看,静下心来总结) 一.总结 1.单选框的如果有多个checked 会以最后一个为准 2.js动态添加checked属性:不行:通过 $(& ...

  2. Android系统开发(5)——Eclipse for C/C++

    一.下载JDK 官方下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 二 ...

  3. Centos配置java环境

    安装jdk JDK 是开发Java程序必须安装的软件,我们查看一下 yum 源里面的 JDK:yum list java* 选择适合本机的JDK,并安装:yum install java-1.7.0- ...

  4. VS_VERSION_INFO

    VS_VERSION_INFO这里可以修改ocx的版本号

  5. angular动画知识点以及代码样例

    原文地址 https://www.jianshu.com/p/4400174072e2 大纲 1.angular动画的相关概念 2.angular动画的绑定方式 3.angular动画代码实例 1.a ...

  6. javascript的全局变量 分类: C1_HTML/JS/JQUERY 2014-08-07 11:03 562人阅读 评论(0) 收藏

    javascipt是一门面向对象的编程语言.由于存在一些全局属性及全局函数,因此可以认为存在一个全局变量,这些全局属性及全局函数均是其属性或函数. 在js核心中,并没有定义一个具体的全局变量,因此,j ...

  7. [Ramda] Compose lenses

    We can compose lenses to get value: const addrs = [{street: '99 Walnut Dr.', zip: '04821'}, {street: ...

  8. 《iOS Human Interface Guidelines》——Segmented Control

    分段控件 分段控件是一组线性段.每一个button相应的功能能够显示一个不同的视图. API NOTE 查看UISegmentedControl来学习很多其它关于在你的代码中定义一个分段控件的内容. ...

  9. Android使用JNI实现Java与C之间传递数据

    介绍Java如何将数据传递给C和C回调Java的方法. java传递数据给C,在C代码中进行处理数据,处理完数据后返回给java.C的回调是Java传递数据给C,C需要用到Java中的某个方法,就需要 ...

  10. 【codeforces 755A】PolandBall and Hypothesis

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...