当前位置:网站首页>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]
边栏推荐
- Zhang Fei hardware 90 day learning notes - personal record on day 6. Please see my personal profile / homepage for the complete record
- QT -- qfile file read / write operation
- 2022-07-02 advanced network engineering (XV) routing policy - route policy feature, policy based routing, MQC (modular QoS command line)
- 2022-07-02 网工进阶(十五)路由策略-Route-Policy特性、策略路由(Policy-Based Routing)、MQC(模块化QoS命令行)
- I didn't cancel
- Pecan — Overview
- Valentine's Day - make an exclusive digital collection for your lover
- These problems should be paid attention to in the production of enterprise promotional videos
- Think of new ways
- Free hand account sharing in September - [cream Nebula]
猜你喜欢
[free sharing] kotalog diary2022 plan electronic manual ledger
Chapter 1: seek common? Decimal and S (D, n)
2022-07-02 网工进阶(十五)路由策略-Route-Policy特性、策略路由(Policy-Based Routing)、MQC(模块化QoS命令行)
Chapter 20: y= sin (x) /x, rambling coordinate system calculation, y= sin (x) /x with profile graphics, Olympic rings, ball rolling and bouncing, water display, rectangular optimization cutting, R que
第一章: 舍罕王失算
The earliest record
Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue
If the warehouse management communication is not in place, what problems will occur?
Chapter 1: find all factorial sums, Grand Prix site unified programming, three factorial sums, graphic point scanning, recursive factorial n of n!, Find the factorial n of n!, King Shehan miscalculate
随机推荐
Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
2022-06-30 网工进阶(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
Bright purple crystal meso tetra (4-aminophenyl) porphyrin tapp/tapppt/tappco/tappcd/tappzn/tapppd/tappcu/tappni/tappfe/tappmn metal complex - supplied by Qiyue
Chapter 2: find the number of daffodils based on decomposition, find the number of daffodils based on combination, find the conformal number in [x, y], explore the n-bit conformal number, recursively
Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue
Acquisition and transmission of parameters in automatic testing of JMeter interface
Octopus online ecological chain tour Atocha protocol received near grant worth $50000
2020 intermediate financial management (escort class)
Sentinel source code analysis part I sentinel overview
3. Data binding
CesiumJS 2022^ 源码解读[7] - 3DTiles 的请求、加载处理流程解析
2. Template syntax
4. Data binding
2022-06-27 网工进阶(十二)IS-IS-开销类型、开销计算、LSP的处理机制、路由撤销、路由渗透
第一章:简化同码小数和s(d, n)
BOC protected tryptophan porphyrin compound (TAPP Trp BOC) Pink Solid 162.8mg supply - Qiyue supply
FPGA learning notes: vivado 2019.1 project creation
Pecan — Overview
Unittest framework is basically used
NFT without IPFs and completely on the chain?