leetcode文章137称号-Single Number II

#include<stdio.h>
#include<stdlib.h>

int singleNumber(int* nums, int numsSize)
{
	int count[32]={0};
	int i,j,number=0;
	for(i=0;i<numsSize;i++)
	{
		for(j=0;j<32;j++)
			count[j]+=((nums[i]&(1<<j))!=0);
	}
	for(i=0;i<32;i++)
	{
		if(count[i]%3!=0)
			number+=(1<<i);
	}
	return number;
}

int main()
{
	int n;
	int i,j=0;
	while(scanf("%d",&n)!=EOF)
	{
		int *nums=(int *)malloc(sizeof(int)*n);
		for(i=0;i<n;i++)
			scanf("%d",&nums[i]);
		j=singleNumber(nums, n);
		printf("%d\n",j);
	}
	return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

时间: 2024-10-12 22:22:21

leetcode文章137称号-Single Number II的相关文章

leetcode第137题-Single Number II

#include<stdio.h> #include<stdlib.h> int singleNumber(int* nums, int numsSize) { int count[32]={0}; int i,j,number=0; for(i=0;i<numsSize;i++) { for(j=0;j<32;j++) count[j]+=((nums[i]&(1<<j))!=0); } for(i=0;i<32;i++) { if(coun

【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? 思路: 用一个32位的数组存每一位bit值之后.得到答案后每一位除

LeetCode 137: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? Single Number II 比Single Number要复杂的多,

leetcode || 137、Single Number II

problem: 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? Hide Tags Bit Manipulation 题

leetCode: Single Number II [137]

[题目] 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? [题意] 给定一个整数以外,其中除了一个整数只出现一次以外,其他

Leetcode 137 Single Number II 仅出现一次的数字

原题地址https://leetcode.com/problems/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 co

LeetCode 136、137:Single Number I &amp; II

Single Number Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Single Number II Given an arr

LeetCodeOJ 137. Single Number II 一题三解

原题链接:https://leetcode.com/problems/single-number-ii/ 题目如下: 137. Single Number II QuestionEditorial Solution My Submissions Total Accepted: 91049 Total Submissions: 235598 Difficulty: Medium Given an array of integers, every element appears three time

[LeetCode][JavaScript]Single Number II

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? https://leetcode.com/