当前位置:网站首页>136. Single Number A number that only appears once
136. Single Number A number that only appears once
2022-08-08 02:34:00 【DXB2021】
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
Given an array of non-empty integers, each element appears twice except one that appears only once.Find the element that appears only once.
Description:
You must implement a solution with a linear runtime complexity and use only constant extra space.
Your algorithm should have linear time complexity.Can you do it without using extra space?
Example 1:Example 1:
Input: nums = [2,2,1]
Output: 1
Enter: [2,2,1]Output: 1
Example 2:Example 2:
Input: nums = [4,1,2,1,2]
Output: 4
Enter: [4,1,2,1,2]Output: 4
Example 3:
Input: nums = [1]
Output: 1
Constraints:
1 <= nums.length <= 3 * 
-3 *
<= nums[i] <= 3 * 
Each element in thearray appears twice except for one element which appears only once.
C language: (XOR operation)
int singleNumber(int* nums, int numsSize){for(int i=1;iExecution result: Passed
Execution time: 16 ms, beat 88.61% of users in all C commits
Memory consumption: 7 MB, beats 61.65% of users in all C commits
Passed test case: 61 / 61
C language: (violence law)
int singleNumber(int* nums, int numsSize){int result;for(int i=0;iExecution result: pass
Execution time: 1020 ms, beats 6.61% of users in all C commits
Memory consumption: 7.1 MB, beats 41.73% of users in all C commits
Passed test case: 61 / 61
边栏推荐
猜你喜欢
随机推荐
SDRAM详解
121. Best Time to Buy and Sell Stock买卖股票的最佳时机
Seven Steps to Hands-On Machine Learning
QML ListView详解
R语言统计与绘图:ROC曲线的统计计算
陈强教授《机器学习及R应用》课程 第四章作业
Docker安装Redis 6.2.6
深入Synchronized各种使用方法
意识的概念框架:我们的意识从注意图式产生?
textplot包:文本语义及可视化
Negative Number Storage and Type Conversion in Program
Detailed QML ListView
Edu Codeforces Round 133 A. 2-3 Moves
在R中使用Matlab函数
LeetCode二叉树系列——144.左叶子之和
Is it safe and reliable to open a securities account?
PTA Exercise 1.8 Binary Search
基于图像二维熵的视频信号丢失检测(Signal Loss Detection)
leetcode 30. 串联所有单词的子串
R语言数据分析-线性代数基础









