[勇者闯LeetCode] 136. Single Number
[勇者闯LeetCode] 136. Single Number
Description
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?
Information
- Tags: Hash Table | Bit Manipulation
- Difficulty: Easy
Solution
两个相同的数字进行异或操作会得到0,而任一数字与0进行异或则得到原来的数字。由于数组只一个数字只出现一次,其他都出现两次,所以对数组中的数字逐个进行异或操作,最后会得到只出现一次的那个数字。
Python Code
class Solution(object):def singleNumber(self, nums):""":type nums: List[int]:rtype: int"""result = 0for num in nums:result ^= numreturn result
[勇者闯LeetCode] 136. Single Number相关推荐
- 【异或】LeetCode 136. Single Number
LeetCode 136. Single Number Solution1:我的答案 还好异或的性质没记错,还好,还好 class Solution { public:int singleNumber ...
- Leetcode 136 Single Number 仅出现一次的数字
原题地址 https://leetcode.com/problems/single-number/ 题目描述 Given an array of integers, every element app ...
- LeetCode 136. Single Number【哈希表/位运算/数学】简单
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12.由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止:由于LeetCode还在不断地创建新 ...
- leetcode 136. Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note: ...
- [swift] LeetCode 136. Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note: ...
- [勇者闯LeetCode] 191. Number of 1 Bits
[勇者闯LeetCode] 191. Number of 1 Bits Description Write a function that takes an unsigned integer and ...
- [勇者闯LeetCode] 6. ZigZag Conversion
[勇者闯LeetCode] 6. ZigZag Conversion Description The string "PAYPALISHIRING" is written in a ...
- [勇者闯LeetCode] 70. Climbing Stairs
[勇者闯LeetCode] 70. Climbing Stairs Description You are climbing a stair case. It takes n steps to rea ...
- 【?异或】LeetCode 260. Single Number III
LeetCode 260. Single Number III Solution1: 博客转载自:http://www.cnblogs.com/grandyang/p/4741122.html 这道题 ...
最新文章
- 第三代测序单分子荧光测序之Pacbio 测序原理
- 对比Javascript和TypeScript
- python numpy矩阵切片和索引的用法(冒号:和省略号...)
- [商业]文件文件夹对比合并工具Araxis Merge
- Buildroot构建指南——Linux内核
- 操作系统实验文件管理_系统设计硬核知识(5)——操作系统的文件管理
- java实现遍历树形菜单方法——映射文件VoteTree.hbm.xml
- day10T1改错记
- mac实现ssh的免密远程登录
- c语言 error2050,c语言程序设计20509new.doc
- [转载] [硕.Love Python] QuickSort(快速排序)
- 阶段3 2.Spring_03.Spring的 IOC 和 DI_1 ioc的概念和作用
- 免费数据集下载网站【dataset】
- 图文详解如何从win8/8.1中文版(核心版)升级到win8/8.1专业版
- 99%的人误解BLM中的“战略”与“执行”的关系及错误认为BLM/BEM就是战略解码的全部!
- PhpSpreadsheet怎么设置单元格边框
- uniapp image 图片自适应
- 计算机类SCI与EI收录的外文期刊
- 我的世界java村民繁殖条件,我的世界:四个新版村民繁殖的基础条件,而且这个指令也要关掉?...
- 高通平台音频audio基本知识概述
热门文章
- 治Android各种疑难杂症
- 男人做事,要克服这些心理弱点
- C++学习之两种向下转型
- 区块链编程:Web3j账户管理练习
- tf.keras.activations.gelu tensorflow1.15.0
- 80C51和ARM的Intel hex解析
- java项目横向越权_横向越权、纵向越权问题解决
- c语言回文字符串用指针,C语言-判断回文字符串【函数+指针】(一)
- java 逻辑运算符的概念和使用
- 整理1986.01-2019.02_国际WTI原油价格日、周、月、年度数据