[LeetCode&Python] Problem 136. Single Number
2024-08-24 08:19:18
Given a non-empty 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?
Example 1:
Input: [2,2,1]
Output: 1
Example 2:
Input: [4,1,2,1,2]
Output: 4
class Solution:
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
nums.sort()
n=len(nums) i=0
while i!=n:
if i==n-1 or nums[i]!=nums[i+1]:
return nums[i]
i+=2
最新文章
- 关于ubuntu16无线网卡RTL8723BE频繁掉线及信号不足的解决办法
- 查找增强出口和BADI程序
- 提升你的开发效率,10 个 NPM 使用技巧
- Random()方法的使用
- UnitTest
- ocp 1Z0-047 131-276题解析
- mysql 一个较特殊的问题:You can't specify target table for update in FROM clause
- im消息丢失插件
- uber在限制新司机加入了,看看新政策把
- ubuntu的常用命令
- cookie笔记(一)
- scrapy爬取极客学院全部课程
- 【UML 建模】在线UML建模工具 ProcessOn 使用详解
- Java Trie字典树,前缀树
- 进程命令(tasklist)
- Redmine(window7)安装
- 【Java基础】浅谈常见设计模式
- ubuntu下定时任务的执行
- VLAN报文和非VLAN以太网报文的区别
- 【洛谷P1198】最大数
热门文章
- [ios]ios读写文件本地数据
- Flutter学习笔记(三)-- 事件交互和State管理
- Java-Java面向对象程序设计
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 问题解决方法
- 在WPF中添加Windows Form控件(包括 ocx控件)
- GitHub出现Permissiondenied (publickey).
- SMTP 发邮件
- 87. Scramble String *HARD* 动态规划
- mybatis标签之——<;trim>;
- POJ 2752 KMP中next数组的理解