Leetcode 137 Single Number II
2015-06-19 23:33
267 查看
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
方法一:原理同 Leetcode 136 Single Number
方法二:Bit Manipulation
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
方法一:原理同 Leetcode 136 Single Number
var singleNumber = function(nums) { var hash = {} for(var i=0; i<nums.length; i++) if(!hash.hasOwnProperty(nums[i])) hash[nums[i]] = 1 else hash[nums[i]] += 1 for(var x in hash) if(hash[x] < 2) return Number(x) }
方法二:Bit Manipulation
相关文章推荐
- Binary Tree Zigzag Level Order Traversal
- GUI--Swing组件(2)
- Centos 6.5系统更改yum源为163
- 阅读笔记之《梦断代码》一
- 因特网
- 搬寝室
- Visual Studio 2012本身都是已经支持Jquery/Javascript智能提示
- Android中常常使用shape来定义控件的一些显示属性
- C语言日志处理
- 广域网优化
- Binary Tree Level Order Traversal
- java单例模式的讨论
- 补第一阶段冲刺站立会议3(应发表日期5月15日)
- 关于数列1,1,2,3,5,8,13,21,34..用C#语言编程求第n项为?
- POJ 1155 树形DP
- 使用ScrollView实现下拉刷新(一)
- linux权限
- Uniform Generator
- CODE[VS] 1214 线段覆盖
- AES Test vectors