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 ...
随机推荐
- 支付宝开通海外退税 阿里腾讯暗战跨境O2O_21世纪网
支付宝开通海外退税 阿里腾讯暗战跨境O2O_21世纪网 支付宝开通海外退税 阿里腾讯暗战跨境O2O
- 使用 Docker 容器应该避免的 10 个事情
当你最后投入容器的怀抱,发现它能解决很多问题,而且还具有众多的优点: 第一:它是不可变的 – 操作系统,库版本,配置,文件夹和应用都是一样的.您可以使用通过相同QA测试的镜像,使产品具有相同的表现. ...
- Magician - hdu 5316 (区间查询合并)
题意:有一个区间,然后有两种操作 1. 把a处的值改为b 0,查询区间ab的子序列的最大和,这个比较特殊,子序列里面相邻的数要有不同的奇偶性 ***************************** ...
- String源码
/* * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETA ...
- java笔记8之选择结构IF
注意1 A比较表达式无论简单还是复杂,结果必须是boolean类型 B:if语句控制的语句体如果是一条语句,大括号可以省略: 如果是多条语句,就不能省略.建议永远不要省 ...
- Runtime.exec()
关于RunTime类的介绍: /** * Every Java application has a single instance of class * <code>Runtime< ...
- 逆拓扑排序 HDU2647Reward
这个题如果用邻接矩阵的话,由于n比较大,会超内存,所以选用邻接表的形式.还有就是这个题有那个等级的问题,一级比一级的福利高,所以不能直接拓扑排序,而是反过来,计算出度,找出度为0的顶点,然后更新出度数 ...
- Linux系统最小化安装之后的系统基础环境安装以及内核优化脚本
#!/bin/bash #添加epel和rpmforge的外部yum扩展源 cd /usr/local/src wget http://mirrors.ustc.edu.cn/fedora/epel/ ...
- C# 面向对象 , 继承
继承 class A { Console.WriteLine("hello world"); } class B:A { } 以上书写,表示B 是A 的子类, B 同时继承A 中 ...
- 用CSS边框图像让你的网站更漂亮
不久之前,添加一些装饰性元素,例如给网页中的图片添加花哨的边,以及耐心调整CSS文件才能使你的网页看起来不错.然而现在CSS已经做出了改变,用复杂的边框装饰你的网站只需几行代码.这篇文章将告诉你如何做 ...