当前位置:网站首页>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]
边栏推荐
- The most valuable thing
- PR FAQ: how to set PR vertical screen sequence?
- 10 smart contract developer tools that miss and lose
- Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
- I didn't cancel
- PR 2021 quick start tutorial, how to create new projects and basic settings of preferences?
- Recommend a GIF processing artifact less than 300K - gifsicle (free download)
- Zhang Fei hardware 90 day learning notes - personal record of day 3, please see my personal profile / homepage for the complete
- 论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
- Today I am filled with emotion
猜你喜欢
Merge K ascending linked lists
第二章:求a,b的最大公约与最小公倍数经典求解,求a,b的最大公约与最小公倍数常规求解,求n个正整数的的最大公约与最小公倍数
Professional interpretation | how to become an SQL developer
第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
2022 - 06 - 30 networker Advanced (XIV) Routing Policy Matching Tool [ACL, IP prefix list] and policy tool [Filter Policy]
03 -- QT OpenGL EBO draw triangle
These problems should be paid attention to in the production of enterprise promotional videos
10 smart contract developer tools that miss and lose
Part 28 supplement (XXVIII) busyindicator (waiting for elements)
2022-06-30 网工进阶(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
随机推荐
IPv6 experiment
Flume learning notes
第二章:求a,b的最大公约与最小公倍数经典求解,求a,b的最大公约与最小公倍数常规求解,求n个正整数的的最大公约与最小公倍数
unittest框架基本使用
Zhang Fei hardware 90 day learning notes - personal records on day 4, please see my personal profile / homepage for the complete
第一章:简化同码小数和s(d, n)
Valentine's Day - make an exclusive digital collection for your lover
Think of new ways
10 smart contract developer tools that miss and lose
Redis master-slave synchronization, clustering, persistence
Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)
2022-06-25 advanced network engineering (XI) IS-IS synchronization process of three tables (neighbor table, routing table, link state database table), LSP, cSNP, psnp, LSP
04 -- QT OpenGL two sets of shaders draw two triangles
Chapter 2: find the classical solution of the maximum Convention and the least common multiple of a and B, find the conventional solution of the maximum Convention and the least common multiple of a a
BOC protected alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC supplied by Qiyu
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?
Day18 - basis of interface testing
JMeter connection database
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
交叉编译Opencv带Contrib