LeetCode 136. Single Number(单个数字)
2016-05-27 00:22
429 查看
原题网址:https://leetcode.com/problems/single-number/
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?
方法:利用异或运算的特性。
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?
方法:利用异或运算的特性。
public class Solution { public int singleNumber(int[] nums) { int single = 0; for(int num: nums) single ^= num; return single; } }
相关文章推荐
- LeetCode 135. Candy(糖果)
- LeetCode 134. Gas Station(加油站)
- LeetCode 132. Palindrome Partitioning II(回文切分)
- LeetCode 133. Clone Graph(克隆图)
- 原型链(__proto__)
- makefile之VPATH和vpath的使用
- System.in.read()
- javascript的 Object 和 Function
- 快速多人游戏(1) - 介绍
- 概率世界
- 如何配置php运行环境
- Share Ubuntu Home Directories using Samba
- php性能测试工具--xhprof
- linux篇——centOs下的vim配置
- dll 子类化 记事本 相应自己的功能
- 用NSMutableAttributedString快速设置UIbutton Title/lable的文字:字体,大小,颜色
- 拦截器getmodel方法什么时候被调用(没搞懂有什么鸟用,自己搭的项目中用到了这个)
- Convention插件的使用(会涉及content目录,jsp必须放入这个下面才能映射成功基于注解的配置)
- Android 动画目录-概要
- 最新版SDWebImage的使用