Single Number
来源:互联网 发布:php if判断语句 编辑:程序博客网 时间:2024/06/05 14:10
Q:
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Using bitwise XOR to find the single number, only the same number can unmark it.
Solution:
public class Solution { public int singleNumber(int[] A) { int n = 0; for (int i = 0; i < A.length; i++) n = n ^ A[i]; return n; }}
0 0
- Single Number
- single number
- Single Number
- Single Number
- Single Number
- Single Number
- Single Number
- Single Number
- Single Number
- Single Number
- Single Number
- Single Number
- Single Number
- Single Number
- single number
- Single Number
- Single Number
- Single Number
- 抽象类与接口的扩展功能
- 面向对象(高级)——接口的基本概念
- 设计模式观后(c++还原之二十二 访问者模式)
- 2015校招最新java面试题及答案(面试前必看)
- Android上实现仿IOS弹性ScrollView
- Single Number
- Linux后台进程管理以及ctrl+z(挂起)、ctrl+c(中断)、ctrl+\(退出)和ctrl+d(EOF)的区别
- 面向对象(高级)——对象的多态性
- 学习Python(一):开始
- 面向对象(高级)————instanceof关键字
- LeetCode Convert Sorted List to Binary Search Tree 解题报告
- 面向对象(高级)抽象类与接口的应用
- HDU 4814 Golden Radio Base 数学 模拟 或者乱搞。。。。
- 〖面向对象(高级)〗_实例分析:宠物商店笔记