【leetcode】Single Number II
int singleNumber(int A[], int n) {
int once = 0;
int twice = 0;
int three = 0;
for (int i = 0; i < n; ++i)
{
//在计算新的once 前,计算twice
twice |= once & A[i];
//计算新的once
once ^= A[i];
three = ~(once & twice);
//将3次的1都清理掉
once &= three;
twice &= three;
}
return once;
}
【leetcode】Single Number II的更多相关文章
- 【题解】【位操作】【Leetcode】Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- 【Leetcode】 - Single Number II
Problem Discription: Suppose the array A has n items in which all of the numbers apear 3 times excep ...
- 【leetcode】Single Number II (medium) ★ 自己没做出来....
Given an array of integers, every element appears three times except for one. Find that single one. ...
- 【LeetCode】Single Number I & II & III
Single Number I : Given an array of integers, every element appears twice except for one. Find that ...
- 【leetcode】Single Number && Single Number II(ORZ 位运算)
题目描述: Single Number Given an array of integers, every element appears twice except for one. Find tha ...
- 【leetcode78】Single Number II
题目描述: 给定一个数组,里面除了一个数字,其他的都出现三次.求出这个数字 原文描述: Given an array of integers, every element appears three ...
- 【Leetcode】【Medium】Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- 【leetcode】Single Number (Medium) ☆
题目: Given an array of integers, every element appears twice except for one. Find that single one. No ...
- 【Leetcode】Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
随机推荐
- Properties的使用
Properties的各种相对路径,绝对路径的用法 所在包: package com.test.javaAPI.collections; import java.io.File; import jav ...
- Linux解压缩总结
看文件名的后缀名,不同的后缀的文件解压和压缩的命令都不一样总结如下: *.tar 用 tar –xvf 解压 *.gz 用 gzip -d或者gunzip 解压 *.tar.gz和*.tgz 用 ta ...
- PowerShell入门(序):为什么需要PowerShell?
原文:http://www.cnblogs.com/ceachy/archive/2013/01/23/PowerShellPreface.html 曾几何时,微软的服务器操作系统因为缺乏一个强大的S ...
- js正则:零宽断言
JavaScript正则表达式零宽断言 var str="abnsdfZL1234nvcncZL123456kjlvjkl"var reg=/ZL(\d{4}|\d{6})(?!\ ...
- session 共享
目前大多数大型网站的服务器都采用了分布式的部署方式,但是session是在服务器端保存的,如果用户跳转到其他服务器的话,session就会丢失,于是就有了分布式系统的session共享问题. sess ...
- There is an error in invoking javac. A full JDK (not just JRE) is required
最近调整了磁盘分区,硬盘里什么都没有了,可惜了我很多项目还有数据库资源然后把以前ssh项目重新导入进来的时候出现了一个错误org.apache.jasper.JasperException: PWC6 ...
- C/C++用strncpy()与strstr()分割与匹配查找字符串
最近做题遇到分割与匹配字符串的题目(hdu5311),看来别人的代码,才知道有strncpy()和strstr()函数,于是搜集了一点资料,记录一下基本用法. 一.strncpy() char * s ...
- 数据结构——二叉搜索树(Binary Search Tree)
二叉树(Binary Tree)的基础下 每个父节点下 左节点小,右节点大. 节点的插入: 若root==NULL则root=newnode 否则不断与节点值比较,较小则向左比较,较大则向右比较. 完 ...
- Android:基于Eclipse编译调试系统级应用源代码
一. 概要描述 在使用Eclipse导入android工程源代码以后,我们可以使用ddms调试和跟踪源代码. 本文讲述动态调试源代码和静态调试源代码的两种方法,避免build system. ...
- cocos2d-x 之Scene和Layer
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...