leetcode 136 Single Number bBt Option
2024-08-31 23:45:55
Linked Url:https://leetcode.com/problems/single-number/
Given a non-empty 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?
Example :
Input: [,,]
Output: 1
Example :
Input: [,,,,]
Output:
solution:
The method is xor option, principles is : 0 xor 0 = 0; 0 xor 1 = 1;any num xor itself = 0,so we pass the array and xor its elements all,so the result which is we want.
Ac code follow:
class Solution {
public:
int singleNumber(vector<int>& nums) {
int res = nums[];
for(int i = ;i < nums.size();++i)
res = nums[i]^res;
return res;
}
};
最新文章
- python3 实现简单的信用卡还款,取款转账功能V2
- UTF-8编码的字符串拆分成单字、获取UTF-8字符串的字符个数的代码及原理
- C语言 homework(4)
- 漫游Kafka设计篇之消息传输的事务定义
- CentOS下几种软件安装方式
- Android Studio rename module Can&#39;t rename root module
- python成长之路15
- 浅析Xilinx 三速以太网MAC IP核
- 文件比较与同步工具——FreeFileSync
- JDK1.8源码(十)——java.util.LinkedHashSet类
- JDK 5~8的特性对比
- 从mysql向HBase+Phoenix迁移数据的心得总结
- SQL Server进阶(十二)函数
- ng-cordova和cordova区别
- oracle中的对象创建及删除语句【原创】
- Spring Boot之初始化项目
- R基础-适合于纯小白
- 修改CSV中的某些值
- 十年WEB技术发展历程
- Java编程环境eclipse配置