【LeetCode】136 & 137 & 260 - Single Number I & II &III
2015-09-29 14:40
471 查看
I.
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?
Hide Tags: Hash Table Bit Manipulation
Hide Similar Problems: (M) Single Number II (M) Single Number III (M) Missing Number (H) Find the Duplicate Number
Solution : Xor
II.
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?
Hide Tags : Bit Manipulation
Hide Similar Problems : (M) Single Number (M) Single Number III
Solution :
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?
Hide Tags: Hash Table Bit Manipulation
Hide Similar Problems: (M) Single Number II (M) Single Number III (M) Missing Number (H) Find the Duplicate Number
Solution : Xor
class Solution { public: int singleNumber(vector<int>& nums){ int ret=0; //it must be initialized for(int i=0;i<nums.size();i++){ ret=ret^nums[i]; } return ret; } };
II.
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?
Hide Tags : Bit Manipulation
Hide Similar Problems : (M) Single Number (M) Single Number III
Solution :
相关文章推荐
- python中的enumerate
- git push 时遇到的问题
- 利用JDBC根据表结构生成ModelClass
- 重写和重载的区别
- Oracle中单引号的使用
- Mac-OSX下Ruby更新
- 新手购买海外VPS主机需要注意的几个账户安全问题
- oracle之trunc与round
- Spring Batch学习之路- 简介(一)
- c# b/s 网站中截取网页图片
- 10 java.lang.ThreadLocal
- linux使用flock文件锁解决脚本重复执行问题
- onload和ready的区别
- java spring quartz定时调度从入门到精通
- leetcode Find the Duplicate Number
- java判断request请求是手机还是pc终端
- maven配置编译路径
- su su -
- jQuery的相关知识点
- 部署dz