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的更多相关文章

  1. 【leetcode】Single Number && Single Number II(ORZ 位运算)

    题目描述: Single Number Given an array of integers, every element appears twice except for one. Find tha ...

  2. 【LeetCode】264. Ugly Number II

    Ugly Number II Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose ...

  3. 【题解】【位操作】【Leetcode】Single Number II

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  4. LightOJ 1245 Harmonic Number (II)(找规律)

    http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS    ...

  5. [OJ] Single Number II

    LintCode 83. Single Number II (Medium) LeetCode 137. Single Number II (Medium) 以下算法的复杂度都是: 时间复杂度: O( ...

  6. [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 ...

  7. Single Number,Single Number II

    Single Number Total Accepted: 103745 Total Submissions: 218647 Difficulty: Medium Given an array of ...

  8. 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 ...

  9. 1245 - Harmonic Number (II)(规律题)

    1245 - Harmonic Number (II)   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 3 ...

随机推荐

  1. EasyUEFI

    ---------------------------------http://www.easyuefi.com/downloads/EasyUEFI_Setup.exe--------------- ...

  2. EMV/PBOC 解析(二) 卡片数据读取

    上一篇简单的了解了IC智能卡的文件结构和APDU报文,这篇我们直接来读取卡内的数据.下面我们主要参照<中国金融集成电路(IC)卡规范>. 好了废话不多说,下面贴指令: (1)卡片接收一个来 ...

  3. java垃圾回收算法

    1.标记-清除 2.标记-复制 3.标记-整理 4.分代混合算法

  4. jenkins服务器安装

    http://www.360doc.com/content/13/0412/09/10504424_277718090.shtml

  5. Eclipse ADT的Custom debug keystore所需证书规格

    最近开始研究Google Play的In-app Billing IAB内置计费API,发现一个比较烦人的问题就是测试时应用必须经过正式签名,而默认Eclipse ADT调试运行使用的是临时生成的De ...

  6. 浅谈Manacher算法与扩展KMP之间的联系

    首先,在谈到Manacher算法之前,我们先来看一个小问题:给定一个字符串S,求该字符串的最长回文子串的长度.对于该问题的求解.网上解法颇多.时间复杂度也不尽同样,这里列述几种常见的解法. 解法一   ...

  7. JAVA实现AES和MD5加密

    package test; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; ...

  8. Linux设备驱动中断机制

    [主要内容] Linux设备驱动编程中的中断与定时器处理 [正文] 一.基础知识 1.中断 所谓中断是指CPU在执行程序的过程中,出现了某些突发事件急待处理,CPU必须暂停执行当前的程序,转去处理突发 ...

  9. C# List集合转Json字符串示例代码

    将list集合转换为Json字符串简单实现代码: public static string GetJosn(List<CalendarInfo> list) { string jsonSt ...

  10. 一个好用的Python备份mysql的脚本

    前几天打算用Python写一个mysql脚本,上Google看了下老外写的,写的挺好的,原地址在http://tecadmin.net/python-script-for-mysql-database ...