首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
只出现一次的数字
[编程题]只出现一次的数字
热度指数:4050
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给定一个整数数组,数组中有一个数出现了一次,其他数出现了两次,请找出只出现了一次的数。
数据范围:数组中元素个数满足
,数组中的元素大小满足
示例1
输入
[1]
输出
1
示例2
输入
[1,2,2]
输出
1
示例3
输入
[2,3,2,1,1]
输出
3
示例4
输入
[-1,2,-1]
输出
2
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(42)
分享
纠错
提交结果有问题?
8个回答
20篇题解
开通博客
代码界的小白
发表于 2022-02-01 15:46:24
题目主要信息 定一个整数数组,数组中有一个数出现了一次,其他数出现了两次,请找出只出现了一次的数。 注意:数组中元素个数1<n<100000 。 方法一:使用hash存储 具体方法 遍历数组,当一个数在map中未出现时,就将该数放入map中,如果当前数在map中已经出现了,就将其移出,最
展开全文
摸鱼学大师
发表于 2022-02-08 14:32:55
题目的主要信息: 一个整数数组,除了一个元素只出现了一次,其他元素都出现了两次 需要找出这个只出现一次的数组 方法一:哈希表 具体做法: 我们可以使用哈希表记录数组元素出现的次数,利用其快速访问特点快速去重。哈希表key值记录遇到的数组元素,第一次遇到次数计为1,后续如果再在哈希表中找到这个数字
展开全文
techferryman
发表于 2023-06-06 09:58:12
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @r
展开全文
CarbonLee
发表于 2024-05-28 21:48:01
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 *
展开全文
17c89
发表于 2024-11-20 12:45:17
import java.util.*; /** * NC231 只出现一次的数字 * @author d3y1 */ public class Solution { // T -> Times 出现次数 private final int T = 2; /**
展开全文
牛客768685351号
发表于 2022-03-13 11:01:09
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型
展开全文
落落LUO
发表于 2024-03-30 10:28:20
异或运算有以下三个性质:1. 任何数和 0 做异或运算,结果仍然是原来的数,即 a⊕0=a;2. 任何数和其自身做异或运算,结果是 0,即 a⊕a=0;3. 异或运算满足交换律和结合律,即 a⊕b⊕a=b⊕a⊕a=b⊕(a⊕a)=b⊕0=b; class Solution { public:
展开全文
辣椒酱up
发表于 2024-03-17 15:27:25
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型
展开全文
辣椒酱up
发表于 2024-03-17 15:28:52
class Solution { public: int singleNumber(vector<int>& nums) { // write code here int n = nums.size(); int ans =
展开全文
热血的乌龟想开了
发表于 2023-07-23 18:17:05
简单的按位异或操作即可 # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型 # class Solution: def singleNumber(self , nums: L
展开全文
问题信息
数组
位运算
难度:
8条回答
42收藏
2108浏览
热门推荐
通过挑战的用户
查看代码
firefly...
2022-09-16 08:39:29
tq要上榜
2022-09-15 16:54:18
正在卷的乌龟很刻苦
2022-09-15 11:19:41
Asphyxiay
2022-09-14 01:14:16
c语言大师
2022-09-12 17:24:54
相关试题
Primary Arithmetic
字符串
基础数学
位运算
评论
(39)
Skew数
基础数学
位运算
评论
(49)
旅行Ⅱ
动态规划
位运算
评论
(1)
预训练商品标题模型时,生僻品牌名(...
大模型开发
评论
(1)
运行以下程序之后,输出的结果为()
C语言
评论
(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]
1
[2,3,2,1,1]
3
[-1,2,-1]
2