题意:先将0, 1, 2, ..., n放入数组,然后去掉其中一个值,找到那个值。

这题与singe number 是一个类型,变形的地方就是首先需要将0, 1, 2, ..., n再次放入这个数组,这样就和singe number 一样。

  1. class Solution {
  2. public:
  3. int missingNumber(std::vector<int>& nums) {
  4. int ans = ;
  5. for (std::vector<int>::size_type i = ; i < nums.size(); ++i){
  6. ans ^= nums[i];
  7. }
  8. for (int i = ; i <= nums.size(); ++i){
  9. ans ^= i;
  10. }
  11. return ans;
  12. }
  13. };

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. [spark]Spark Streaming教程

      (一)官方入门示例 废话不说,先来个示例,有个感性认识再介绍. 这个示例来自spark自带的example,基本步骤如下: (1)使用以下命令输入流消息: $ nc -lk 9999 (2)在一个 ...

  2. 恢复SLAVE上的某几张表的简要方法

    同步报错是遇到最多的一个问题,如果你修复后发现还没有解决,通常的方法就是在Master上重新dump出一份,然后在slave上恢复.这个方法是针对整个库不是很大的情况下使用的,那如果是较大,全部dum ...

  3. AIR 初步 Javascript学习之cookie操作

    //设置cookie的名称,值,过期时间         function setCookie(cookieName,cookieValue,cookieExpire) {             v ...

  4. 键盘钩子监测按键后,获取键码及按键名称(MFC)

    LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam){ if(nCode ==HC_ACTION & ...

  5. VC ADO “ParameterDirectionEnum”:“enum” 类型等 重定义问题 解决方案

    原因分析: 1.在头文件中: #import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace ...

  6. [RxJS] Multicast with a selector argument, as a sandbox

    Let's explore a different use of the multicast() operator in RxJS, where you can provide a selector ...

  7. oracle数据库未打开解决的方法

    Microsoft Windows [版本号 6.1.7601] 版权全部 (c) 2009 Microsoft Corporation.保留全部权利. C:\Users\Administrator& ...

  8. Voronoi Diagram——维诺图

    Voronoi图定义   任意两点p 和q 之间的欧氏距离,记作 dist(p, q) .就平面情况而言,我们有           dist(p, q) =  (px-qx)2+ (py-qy)2 ...

  9. 如何在移动web模仿客户端给input输入框添加自定义清除按钮

    项目有个需求就是在input输入框添加清除按钮,网上查找资料加上自己琢磨终于弄出来了. 灵感来自于 http://www.zhangxinxu.com/wordpress/?p=4077 由于项目已经 ...

  10. 嵌入式linux串口编程(二)

    /*com_writer.c*/#include "uart_api.h" int main(void){ int fd; char buff[BUFFER_SIZE]; if(( ...