博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Leetcode——136. Single Number
阅读量:4137 次
发布时间:2019-05-25

本文共 392 字,大约阅读时间需要 1 分钟。

题目

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?

解答

使用异或运算,XOR!!!

大杀器!!!

本来我想使用unordered_map的,但是需要额外的空间。

class Solution {
//using xorpublic: int singleNumber(vector
& nums) { int res=nums[0]; for(int i=1;i

转载地址:http://eexvi.baihongyu.com/

你可能感兴趣的文章
Ubuntu Could not open lock file /var/lib/dpkg/lock - open (13:Permission denied)
查看>>
collect2: ld returned 1 exit status
查看>>
C#入门
查看>>
C#中ColorDialog需点两次确定才会退出的问题
查看>>
数据库
查看>>
nginx反代 499 502 bad gateway 和timeout
查看>>
linux虚拟机安装tar.gz版jdk步骤详解
查看>>
python实现100以内自然数之和,偶数之和
查看>>
python数字逆序输出及多个print输出在同一行
查看>>
苏宁产品经理面经
查看>>
百度产品经理群面
查看>>
去哪儿一面+平安科技二面+hr面+贝贝一面+二面产品面经
查看>>
element ui 弹窗在IE11中关闭时闪现问题修复
查看>>
vue 遍历对象并动态绑定在下拉列表中
查看>>
Vue动态生成el-checkbox点击无法选中的解决方法
查看>>
MySQL Tricks1
查看>>
python 变量作用域问题(经典坑)
查看>>
pytorch
查看>>
pytorch(三)
查看>>
ubuntu相关
查看>>