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

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

题目: 

Given an array of integers, every eleme:nt 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?

思路:给定一个数组,其中只有一个数是只出现 一次,其它都是出现两次,用按位异或来解,因为相同的两个数的异或肯定为0,最后只剩下了那个只出现 过一次的数。

代码:

class Solution {public:    int singleNumber(vector
& nums) { int result=0; for(int i=0;i

 

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

你可能感兴趣的文章
MongoDB安装及使用
查看>>
mysql安装与配置及Can't connect to MySQL server on localhost (10061)解决办法
查看>>
gensim安装教程
查看>>
python GENSIM训练word2vec流程及遇到问题详解
查看>>
Linux更新python方法及报错处理
查看>>
Python3中无法导入ssl模块的解决办法和python3.7 ModuleNotFoundError: No module named bz2解决办法
查看>>
Linux下mysql数据库安装教程详解
查看>>
windows下mysql数据库迁移到linux方法
查看>>
ImportError: cannot import name ‘HTMLParseError‘ from ‘html.parser‘ (/lib/python3.7/html/parser.py)
查看>>
Linux查看CPU及核数方法
查看>>
java下载图片示例
查看>>
ubuntu14.04.2搭建MPI环境
查看>>
Ubuntu14.04上Hadoop安装问题之解决方案
查看>>
vi编辑下加载行号
查看>>
centOS终端下修改字体
查看>>
centos安装wine
查看>>
Ubuntu 终端打开方式
查看>>
2014-8-21
查看>>
常见传感器的红外(IR)和红光(R)波段
查看>>
2014年07月23日
查看>>