1、题目
给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。
说明:
你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?
示例 1:
输入: [2,2,1] 输出: 1
示例 2:
输入: [4,1,2,1,2] 输出: 4
2、我的解答(copy力扣官方答案)
1 # -*- coding: utf-8 -*- 2 # @Time : 2020/3/14 23:09 3 # @Author : SmartCat0929 4 # @Email : 1027699719@qq.com 5 # @Link : https://github.com/SmartCat0929 6 # @Site : 7 # @File : 136. Single Number.py 8 from typing import List 9 10 11 class Solution: 12 def singleNumber(self, nums: List[int]) -> int: 13 # 亦或运算 14 a = 0 15 for i in nums: 16 a ^= i 17 return a 18 19 20 print(Solution().singleNumber([7, 1, 1, 7, 6, 5, 6]))
LeetCode练题——53. Maximum Subarray
原文:https://www.cnblogs.com/Smart-Cat/p/12495243.html