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 ...
随机推荐
- JS 时间格式CST转GMT
近几天,在做百度地图时,需要转换时间格式并做显示,但是发现显示的时间格式,出现了错乱,二者的日期和小时都出现了变动.例如: 原始时间格式:Thu Aug 18 20:38:54 CST 2016 转换 ...
- web前端面试试题总结---javascript篇
JavaScript 介绍js的基本数据类型. Undefined.Null.Boolean.Number.String. ECMAScript 2015 新增:Symbol(创建后独一无二且不可变的 ...
- poj 3229 The Best Travel Design ( 图论+状态压缩 )
The Best Travel Design Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1359 Accepted: ...
- Computer Vision and Machine Learning Competitions
一.ImageNet Object Detection, Object Classification+Localization 二.COCO Image Captioning 三.LFW Face R ...
- msxml 操作xml
1.简介 在.NET平台,微软为C#或托管C++程序员提供了丰富的类库,用以支持各种需求,其中就有对XML文件操作的丰富的类.例如XMLDocument, XmlElement等.但是C++标准库中并 ...
- Linux磁盘分区实战案例
一.查看新添加磁盘 [root@localhost /]# fdisk -l 磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区 Units = ...
- Resizing LVM Logical Volumes-lvextend
1. fdisk命令/dev/sdc再分出一个sdc2分区 [root@rhel7 ~]# fdisk /dev/sdc Welcome to fdisk (util-linux ). Changes ...
- 一个好用的Python备份mysql的脚本
前几天打算用Python写一个mysql脚本,上Google看了下老外写的,写的挺好的,原地址在http://tecadmin.net/python-script-for-mysql-database ...
- Python元组、列表--笔记
<Python3 程序开发指南> 序列包括元组和列表,首先,我们介绍元组. 元组--tuple 元组为有序的序列,元组和字符串一样也是固定的,不能替换或删除其中的任意数据项.如果需要修改应 ...
- css02基本选择器
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...