LeetCode_Single Number 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?
分析: 统计每一位1出现的个数,最后摸3求余数,1则置最终位为1
class Solution {
public:
int singleNumber(int A[], int n) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int res = ;
int x, sum; for(int i = ; i < ; ++i){ sum = ;
x = (<<i); for(int j = ; j< n; ++j)
if(A[j]&x)
++sum; sum = sum%; if(sum == )
res |= x;
} return res;
}
};
LeetCode_Single Number II的更多相关文章
- 【leetcode】Single Number && Single Number II(ORZ 位运算)
题目描述: Single Number Given an array of integers, every element appears twice except for one. Find tha ...
- 【LeetCode】264. Ugly Number II
Ugly Number II Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose ...
- 【题解】【位操作】【Leetcode】Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- LightOJ 1245 Harmonic Number (II)(找规律)
http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS ...
- [OJ] Single Number II
LintCode 83. Single Number II (Medium) LeetCode 137. Single Number II (Medium) 以下算法的复杂度都是: 时间复杂度: O( ...
- [Locked] Strobogrammatic Number & Strobogrammatic Number II & Strobogrammatic Number III
Strobogrammatic Number A strobogrammatic number is a number that looks the same when rotated 180 deg ...
- Single Number,Single Number II
Single Number Total Accepted: 103745 Total Submissions: 218647 Difficulty: Medium Given an array of ...
- Ugly Number,Ugly Number II,Super Ugly Number
一.Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are po ...
- 1245 - Harmonic Number (II)(规律题)
1245 - Harmonic Number (II) PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 3 ...
随机推荐
- Robot Framework selenium2library 常用关键字
Selenium Library SeleniumLibrary is a Robot Framework test library that uses the popular Selenium we ...
- 给Eclipse提速的7个技巧(转载的)
大约一个月前,我发表了一篇博客,其中介绍了对Eclipse的爱与恨. 有些人问我如何给Eclipse提速,这篇文章就来讨论这个问题.顺带提一下,这篇文章不是比较IDE,所以不要说你讨厌某个IDE而 ...
- web前端面试试题总结---css篇
CSS 介绍一下标准的CSS的盒子模型?低版本IE的盒子模型有什么不同的? (1)有两种, IE 盒子模型.W3C 盒子模型: (2)盒模型: 内容(content).填充(padding).边界(m ...
- iOS UITextField 设置内边距
[self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingTop"]; [self.your ...
- floor() 和 ceil()函数
在C语言的库函数中,floor函数的语法例如以下: #include <math.h> double floor( double arg ); 功能: 函数返回參数不大于arg的最大整数. ...
- Android - ContentProvider机制
以下资料摘录整理自老罗的Android之旅博客,是对老罗的博客关于Android底层原理的一个抽象的知识概括总结(如有错误欢迎指出)(侵删):http://blog.csdn.net/luosheng ...
- 用win32API 实现TextBox水印特效
demo效果:
- Android开发手记(12) Menu的使用
Android中的Menu分为三种,分别为:OptionsMenu(选项菜单).ContextMenu(上下文菜单).SubMenu(子菜单). 1.OptionsMenu 按Menu键就会显示,用于 ...
- 如何清理多余的Windows桌面右键菜单
删除多余的发送到选项 Win7使用一段时间后,我们可能会装很多软件,这时候右键菜单可能会变得很长,特别是“发送到(Send to)”里面的选项,有时候我们卸载软件之后在右键发送到菜单里还会有残存的选项 ...
- Ubuntu桌面版与服务器版有什么不同?
提到安装Linux,Ubuntu可谓是最受欢迎的.为了满足每个人的需求,出现了不少版本或风格的Ubuntu;其中两项便是桌面版与服务器版.只要发布版本号一致,这两者从核心来说也就是相同的,唯 ...