当前位置:网站首页>Leetcode daily question brushing record --540 A single element in an ordered array
Leetcode daily question brushing record --540 A single element in an ordered array
2022-07-01 09:01:00 【Xiaobai 007】
leetcode Record of writing questions
540. A single element in an ordered array
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
class Solution {
public int singleNonDuplicate(int[] nums) {
for(int i = 1;i < nums.length;i+=2){
if(nums[i] != nums[i - 1]){
return nums[i-1];
}
}
return nums[nums.length - 1];
}
}
tip: For the first time, the code idea is the same as that of sister Sanye , Very, very happy ~ Hey !
边栏推荐
- 固定资产管理系统让企业动态掌握资产情况
- Mysql8.0 learning record 17 -create table
- Differences among tasks, threads and processes
- Brief introduction to AES
- Redis源码学习(29),压缩列表学习,ziplist.c(二)
- How to manage fixed assets well? Easy to point and move to provide intelligent solutions
- ARM v7的体系结构A、R、M区别,分别应用在什么领域?
- 中断与其他函数共享变量、临界资源的保护
- Pain points and solutions of equipment management in large factories
- 易点易动助力企业设备高效管理,提升设备利用率
猜你喜欢

Dynamic proxy

Only in China! Alicloud container service enters the Forrester leader quadrant

Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month

Football and basketball game score live broadcast platform source code /app development and construction project

What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?

It is designed with high bandwidth, which is almost processed into an open circuit?

19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition

FAQ | FAQ for building applications for large screen devices

FreeRTOS学习简易笔记

Pain points and solutions of equipment management in large factories
随机推荐
Interrupt sharing variables with other functions and protection of critical resources
Redis -- lattice connects to redis cluster
JCL 和 SLF4J
How can enterprises and developers take the lead in the outbreak of cloud native landing?
How to effectively align team cognition
Ape anthropology topic 20 (the topic will be updated from time to time)
Principle and application of single chip microcomputer timer, serial communication and interrupt system
R语言观察日志(part24)--初始化设置
[interview brush 101] linked list
美团2022年机试
What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
Understand shallow replication and deep replication through code examples
AVL树的理解和实现
Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
An overview of the design of royalties and service fees of mainstream NFT market platforms
Foundation: 3 Opencv getting started images and videos
毕业季,我想对你说
Shell脚本-select in循环
如何高效拉齐团队认知
Is it safe to dig up money and make new shares