From bd19f160a9dc33894732f24451dc19c2aa6ea2ff Mon Sep 17 00:00:00 2001 From: initc <1875919175@qq.com> Date: Sat, 27 Feb 2016 13:09:00 +0800 Subject: [PATCH] add SingleNumberTwo --find three time number except one --- bin/.gitignore | 1 + src/com/jie/SingleNumberTwo.java | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 bin/.gitignore create mode 100644 src/com/jie/SingleNumberTwo.java diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..c2d9872 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/com/ diff --git a/src/com/jie/SingleNumberTwo.java b/src/com/jie/SingleNumberTwo.java new file mode 100644 index 0000000..16a9df1 --- /dev/null +++ b/src/com/jie/SingleNumberTwo.java @@ -0,0 +1,30 @@ +package com.jie; + +public class SingleNumberTwo { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + + public int singleNumber(int[] nums) { + int [] count = new int[32]; + int result=0; + for(int i=0;i<32;i++){ + for(int j=0;j>>i)&1; + } + //获取那一个只出现了一次的数 因为除了一个每一个数都出现了三次 所以我们出现的数的 + //和肯定是三的倍数 最后一个没有出现的数 要不然是0要不然是1 所以%3即可 + count[i]=count[i]%3==0?0:1; + } + //构造最后的结果 + for(int i=0;i<32;i++){ + + result|=count[i]<