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 ...
随机推荐
- Python模拟登录实战(三)
目标:模拟登录知乎 代码如下: #!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'ziv·chan' import re impor ...
- 家族企业的常青之道——leo鉴书68
<Leo鉴书(第1辑)>已登陆百度阅读,今后还将不断更新.免费下载地址:http://t.cn/RvawZEx 企业怎样长久传承.怎样长期有效操持活力.是多元化经营还是集中精力打一点,这些 ...
- [Unit Testing] Angular Test component with required
export default (ngModule) => { describe('Table Item component', () => { let $compile, directiv ...
- 01标题背包水章 HDU2955——Robberies
原来是dp[i],它代表的不被抓的概率i这最大的钱抢(可能1-100) 客是dp[i]表示抢了i钱最大的不被抓概率,嗯~,弱菜水题都刷不动. 那么状态转移方程就是 dp[i]=max(dp[i],dp ...
- valgrind 的使用及错误信息分析
这里记录一下使用valgrind查找你的应用程序中的各种潜在的错误信息,并举例说明. 经常使用valgrind查找一下你的代码的内存有关错误,对移植到嵌入系统后的系统稳定性来说有着重要的意 ...
- 纯CSS3实现超立体的3D图片侧翻倾斜效果
看到网友分享的一款CSS3 3D图片侧翻倾斜特效,觉得效果非常棒,其实话说回来,这玩意儿的实现真的非常简单,主要是创意不错.先来看看效果图.那么接下来我们分析一下源码吧,显示html代码,非常简单: ...
- xheditor编辑器上传截图图片抓取远程图片代码
xheditor是一款很不错的开源编辑器,用起来很方便也很强大. 分享一个xheditor直接上传截图的问题解决方法. 第一步.设置参数 localUrlTest:/^https?:\/\/[^\/] ...
- linux定时任务2-at命令
定时执行命令: [root@rheltest1 ~]# at now + 1 minute //一分钟后执行下面的任务 at> date >> /tmp/test_date.log ...
- MyEclipse修改servlet模版
找到myeclipse安装目录中的 然后把这个jar包复制到桌面 以压缩包的方式打开 之后保存, 然后把修改的这个jar包放到刚开的路径,替换已经存在的! 完成!
- Windows7电脑上不去网,ipconfig查询时默认网关会出现0.0.0.0问题的解决
用ipconfig查看网络配置,发现其他都正确,唯独默认网关上多了一条0.0.0.0的记录,.禁用网络连接再启用也不能恢复.网上找了一下有说改注册表的,打开注册表找到 HKEY_LOCAL_MACHI ...