首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
只出现一次的数字(二)
[编程题]只出现一次的数字(二)
热度指数:2493
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给定一个整数数组,数组中有一个数出现了一次,其他数出现了三次,请找出只出现了一次的数。
数据范围:数组大小满足
,数组中每个元素大小满足
示例1
输入
[1]
输出
1
示例2
输入
[1,2,2,2]
输出
1
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(31)
分享
纠错
提交结果有问题?
9个回答
10篇题解
开通博客
我已入魔
发表于 2022-01-28 11:38:04
思路:这题思路是把数字拆分成位。int型是C++的内置类型,一般机器上为32位,本题中条件特殊每个数字都有出现k次,只有一个数字出现一次,自然想到对每位上的数字求和后%k,这样求余得到的数字就是我们所想要的。 class Solution { public: /** * 代码中的类
展开全文
fred-coder
发表于 2021-11-26 20:43:05
利用计数器统计数量,排序后输出最小值的 key # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # from collections import Counter class
展开全文
17c89
发表于 2024-11-20 12:49:01
import java.util.*; /** * NC227 只出现一次的数字(二) * @author d3y1 */ public class Solution { // T -> Times 出现次数 private final int T = 3;
展开全文
苦行潜修者
发表于 2024-04-23 08:27:36
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param num
展开全文
牛客768685351号
发表于 2022-03-12 12:44:47
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型
展开全文
牛客220889346号
发表于 2024-04-17 11:09:25
描述给定一个整数数组,数组中有一个数出现了一次,其他数出现了三次,请找出只出现了一次的数。思路:循环遍历整个数组,当数在数组中,初始出现的地址和最后出现的地址相同时,则表明该数只出现了一次,返回该数即可。/** /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
展开全文
牛小扭
发表于 2022-05-14 20:38:31
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ function singleNumber( nums ) { // write code he
展开全文
奶ve
发表于 2024-05-12 19:44:46
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型
展开全文
17c89
发表于 2024-11-21 11:33:57
import java.util.*; /** * NC227 只出现一次的数字(二) * @author d3y1 */ public class Solution { // T -> Times 出现次数 private final int T = 3;
展开全文
牛客338107602号
发表于 2022-12-29 21:49:48
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 *
展开全文
问题信息
数组
位运算
难度:
9条回答
31收藏
3579浏览
热门推荐
通过挑战的用户
查看代码
sunuv
2022-09-16 09:38:39
firefly...
2022-09-16 08:38:09
tq要上榜
2022-09-15 16:58:47
正在卷的乌龟很刻苦
2022-09-15 11:09:18
Asphyxiay
2022-09-14 01:12:42
相关试题
旅行Ⅱ
动态规划
位运算
评论
(1)
Primary Arithmetic
字符串
基础数学
位运算
评论
(39)
Skew数
基础数学
位运算
评论
(49)
不系统的进行全面测试,但可以发现一...
软件测试
评论
(1)
以下闭包代码中,调用 functi...
Python
评论
(1)
只出现一次的数字(二)
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ public int singleNumber (int[] nums) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型 */ int singleNumber(vector
& nums) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution: def singleNumber(self , nums ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ public int singleNumber (List
nums) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ function singleNumber( nums ) { // write code here } module.exports = { singleNumber : singleNumber };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution: def singleNumber(self , nums: List[int]) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ func singleNumber( nums []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param numsLen int nums数组长度 * @return int整型 */ int singleNumber(int* nums, int numsLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution def singleNumber(nums) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ def singleNumber(nums: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ fun singleNumber(nums: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ public int singleNumber (int[] nums) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ export function singleNumber(nums: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ func singleNumber ( _ nums: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ pub fn singleNumber(&self, nums: Vec
) -> i32 { // write code here } }
[1]
1
[1,2,2,2]
1