268. Missing Number
2016-04-19 12:39
134 查看
Given an array containing n distinct numbers taken from
For example,
Given nums =
Note:
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
Similar:
41. First Missing Positive
136. Single Number
287. Find the Duplicate Number
0, 1, 2, ..., n, find the one that is missing from the array.
For example,
Given nums =
[0, 1, 3]return
2.
Note:
Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
Similar:
41. First Missing Positive
136. Single Number
287. Find the Duplicate Number
public class Solution { public int missingNumber(int[] nums) { int xor = 0; for (int i = 0; i < nums.length; i++) { xor ^= i ^ nums[i]; } xor ^= nums.length; return xor; } }
相关文章推荐
- leetcode-Binary Tree Inorder Traversal
- 第一阶段冲刺总结01
- 3.跟我学Gradle-快速入门,了解创建和指定Gradle项目的标准目录结构
- Oracle编程入门经典 第6章 在Oracle中处理语句
- HTML加载顺序总结测试
- ShellExecute
- Oracle编程入门经典 第4章 新9i示例模式
- leetcode- Isomorphic Strings
- 深入理解JVM(三)——垃圾收集策略详解
- 深入理解JVM(三)——垃圾收集策略详解
- 将一个十六进制“字符串”转换为十进制数值的问题
- 【转】Ubuntu网卡配置
- C#解压缩文件
- 安装应用
- 编译hive源码导入到eclipse中
- HDU 1429 胜利大逃亡(续) (状态压缩+BFS)
- adb devices -l找不到设备解决方法
- 编程挑战1:抽签问题
- JVM的内存区域划分
- DB2 日期相减