原题目提示可以使用位运算,但是不会用 public class Solution {public int singleNumber(int[] nums) {int res = 0;Arrays.sort(nums);for (int a : nums)System.out.println(a);int i = 0;int j = 0;while (i < nums.length) {if (i
【题目】 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 with
描述 给一个数组,只有一个数字重复1次,其他数字重复三次,找出重复一次数字。 Solution 这道题是之前那道 Single Number单独的数字 的延伸,我们可以建立一个32位的数字,来统计每一位上1出现的个数,我们知道如果某一位上为1的话,那么如果该整数出现了三次,对3去余为0,我们把每个数的对应位都加起来对3取余,最终剩下来的那个数就是单独的数字。 class Solution
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