当前位置:网站首页>Leetcode daily question solution: 540 A single element in an ordered array
Leetcode daily question solution: 540 A single element in an ordered array
2022-07-03 19:40:00 【Xiaoxinxin's Xiaozhai】
Give you an ordered array of integers only , Each of these elements will appear twice , Only one number will appear once .
Please find and return the number that only appears once .
The solution you design must meet O(log n) Time complexity and O(1) Spatial complexity .
Example 1:
Input : nums = [1,1,2,3,3,4,4,8,8]
Output : 2
Example 2:
Input : nums = [3,3,7,7,10,11,11]
Output : 10
Their thinking : Try it first Counter Function calculation array nums The number of occurrences of each element in , Then find the output that appears once
Code :
class Solution:
def singleNonDuplicate(self, nums: List[int]) -> int:
return [i for i,j in Counter(nums).items() if j==1 ][0]
边栏推荐
- UE source code analysis: uccharactermovementcomponent - rootmotion
- Chapitre 1: le roi de shehan a mal calculé
- Thinking about festivals
- 2022 - 06 - 30 networker Advanced (XIV) Routing Policy Matching Tool [ACL, IP prefix list] and policy tool [Filter Policy]
- Professional interpretation | how to become an SQL developer
- Xctf attack and defense world crypto advanced area best_ rsa
- Octopus online ecological chain tour Atocha protocol received near grant worth $50000
- Use unique_ PTR forward declaration? [repetition] - forward declaration with unique_ ptr? [duplicate]
- I didn't cancel
- 交叉编译Opencv带Contrib
猜你喜欢

Common text labels

第一章:喝汽水,阶梯电费计算,阶梯电费计算函数,个人所税,求解平方根不等式,简化求解平方根不等式,求解调和级数不等式,解不等式:d<1+1/2-1/3+1/4+1/5-1/6+..士1/n

Chapter 1: drinking soft drinks, step tariff calculation, step tariff calculation function, personal income tax, solving square root inequality, simplifying solving square root inequality, solving dem

During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution

2022-06-30 网工进阶(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】

2022-06-25 网工进阶(十一)IS-IS-三大表(邻居表、路由表、链路状态数据库表)、LSP、CSNP、PSNP、LSP的同步过程

第一章: 舍罕王失算

2022-07-02 advanced network engineering (XV) routing policy - route policy feature, policy based routing, MQC (modular QoS command line)

Phpstudy set LAN access

Chapter 1: seek common? Decimal and S (D, n)
随机推荐
Read the paper glodyne global topology preserving dynamic network embedding
These problems should be paid attention to in the production of enterprise promotional videos
2022-06-30 网工进阶(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
[free sharing] kotalog diary2022 plan electronic manual ledger
IPv6 experiment
Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
Realize user registration and login
Chapter 1: simplify the same code decimal sum s (D, n)
What is the difference between a kill process and a close process- What are the differences between kill process and close process?
Flume learning notes
Detailed explanation of shuttle unity interworking principle
The necessity of lean production and management in sheet metal industry
Professional interpretation | how to become an SQL developer
How to check the permission to write to a directory or file- How do you check for permissions to write to a directory or file?
Comments on flowable source code (37) asynchronous job processor
Summary of 90 day learning materials and notes of Zhang Fei's actual electronic hardware engineer
第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
Day_ 18 IO stream system
Part 27 supplement (27) buttons of QML basic elements
unittest框架基本使用