`
blue2048
  • 浏览: 184858 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

[leetcode]Single Number II - java

阅读更多
分别存储每一个bit位1出现的次数,然后对3取模
public class Solution {
    public int singleNumber(int[] A) {
         int[] bitNum = new int[32];
        int result =0;
        for (int j = 0; j < 32; j++) {
            for (int i = 0; i < A.length; i++) {
                int ele = A[i];
                int ifExist = ele & (1 << j);
                if (ifExist != 0) {
                    bitNum[j] = ++bitNum[j];
                }
            }
            bitNum[j] = bitNum[j]%3;
            if(bitNum[j] != 0){
                result |= bitNum[j]<<j;
            }
        }
        return result;    
    }
}
 
分享到:
评论

相关推荐

    leetcode答案-leetcode-java:leetcode的Java代码

    答案leetcode-java leetcode.com 的 Java 答案 ================索引================ com.leetcode.array Search a 2D Matrix Spiral Matrix com.leetcode.list Linked List Cycle Linked List Cycle II Remove ...

    Leetcode的ac是什么意思-LeetCodeInJava:leetcode-java

    Leetcode的ac是什么意思 LeetCodeInJava List #98 Validate Binary Search Tree #100 Same Tree #104 Maximum Depth of Binary Tree #122 Best Time to Buy and Sell Stock II #136 Single Number #150 Evaluate ...

    LeetCode:LeetCode解决方案

    preorder-traversal链表reorder-list链表linked-list-cycle-ii链表linked-list-cycle动态规划word-break-ii动态规划word-break链表copy-list-with-random-pointer复杂度single-number-ii复杂度single-number动态规划

    leetcode java

    - "数组中两个数字只出现一次"(Single Number II)则是进一步考察位运算技巧。 ** Miscellaneous(杂项)** 杂项部分包括了一些不那么容易归类的问题,如螺旋矩阵(Spiral Matrix)、整数转罗马数字(Integer to ...

    LeetCode:LeetCode题解

    LeetCode LeetCode题解 传送门 # 标题 解决方案 困难 笔记 1个 简单的 3 简单的 7 简单的 ... Java ...Java ... Java ...Java ... Java ... Java ... Java ...Java ... Single_NumberII Java 中等的 167 Two_Sum_II_Input_

Global site tag (gtag.js) - Google Analytics