[勇者闯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相关推荐

  1. 【异或】LeetCode 136. Single Number

    LeetCode 136. Single Number Solution1:我的答案 还好异或的性质没记错,还好,还好 class Solution { public:int singleNumber ...

  2. Leetcode 136 Single Number 仅出现一次的数字

    原题地址 https://leetcode.com/problems/single-number/ 题目描述 Given an array of integers, every element app ...

  3. LeetCode 136. Single Number【哈希表/位运算/数学】简单

    本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12.由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止:由于LeetCode还在不断地创建新 ...

  4. leetcode 136. Single Number

    Given an array of integers, every element appears twice except for one. Find that single one. Note: ...

  5. [swift] LeetCode 136. Single Number

    Given an array of integers, every element appears twice except for one. Find that single one. Note: ...

  6. [勇者闯LeetCode] 191. Number of 1 Bits

    [勇者闯LeetCode] 191. Number of 1 Bits Description Write a function that takes an unsigned integer and ...

  7. [勇者闯LeetCode] 6. ZigZag Conversion

    [勇者闯LeetCode] 6. ZigZag Conversion Description The string "PAYPALISHIRING" is written in a ...

  8. [勇者闯LeetCode] 70. Climbing Stairs

    [勇者闯LeetCode] 70. Climbing Stairs Description You are climbing a stair case. It takes n steps to rea ...

  9. 【?异或】LeetCode 260. Single Number III

    LeetCode 260. Single Number III Solution1: 博客转载自:http://www.cnblogs.com/grandyang/p/4741122.html 这道题 ...

最新文章

  1. 第三代测序单分子荧光测序之Pacbio 测序原理
  2. 对比Javascript和TypeScript
  3. python numpy矩阵切片和索引的用法(冒号:和省略号...)
  4. [商业]文件文件夹对比合并工具Araxis Merge
  5. Buildroot构建指南——Linux内核
  6. 操作系统实验文件管理_系统设计硬核知识(5)——操作系统的文件管理
  7. java实现遍历树形菜单方法——映射文件VoteTree.hbm.xml
  8. day10T1改错记
  9. mac实现ssh的免密远程登录
  10. c语言 error2050,c语言程序设计20509new.doc
  11. [转载] [硕.Love Python] QuickSort(快速排序)
  12. 阶段3 2.Spring_03.Spring的 IOC 和 DI_1 ioc的概念和作用
  13. 免费数据集下载网站【dataset】
  14. 图文详解如何从win8/8.1中文版(核心版)升级到win8/8.1专业版
  15. 99%的人误解BLM中的“战略”与“执行”的关系及错误认为BLM/BEM就是战略解码的全部!
  16. PhpSpreadsheet怎么设置单元格边框
  17. uniapp image 图片自适应
  18. 计算机类SCI与EI收录的外文期刊
  19. 我的世界java村民繁殖条件,我的世界:四个新版村民繁殖的基础条件,而且这个指令也要关掉?...
  20. 高通平台音频audio基本知识概述

热门文章

  1. 治Android各种疑难杂症
  2. 男人做事,要克服这些心理弱点
  3. C++学习之两种向下转型
  4. 区块链编程:Web3j账户管理练习
  5. tf.keras.activations.gelu tensorflow1.15.0
  6. 80C51和ARM的Intel hex解析
  7. java项目横向越权_横向越权、纵向越权问题解决
  8. c语言回文字符串用指针,C语言-判断回文字符串【函数+指针】(一)
  9. java 逻辑运算符的概念和使用
  10. 整理1986.01-2019.02_国际WTI原油价格日、周、月、年度数据