当前位置:网站首页>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 !
边栏推荐
- Software Engineer Interview Question brushing website and experience method
- Shell script -while loop explanation
- 【MFC开发(16)】树形控件Tree Control
- Nacos - gestion de la configuration
- 钓鱼识别app
- Yolov3, 4, 5 and 6 Summary of target detection
- Phishing identification app
- FreeRTOS learning easy notes
- Foundation: 3 Opencv getting started images and videos
- Principle and application of single chip microcomputer timer, serial communication and interrupt system
猜你喜欢

Principles of Microcomputer - Introduction

Microcomputer principle - bus and its formation

Phishing identification app

FreeRTOS learning easy notes

5mo3 UHI HII HII 17mn4 19Mn6 executive standard

大型工厂设备管理痛点和解决方案

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

Vsync+ triple cache mechanism +choreographer

Glitch free clock switching technology

Bimianhongfu queren()
随机推荐
如何解决固定资产管理和盘点的难题?
R语言观察日志(part24)--初始化设置
Foundation: 2 The essence of image
Nacos - gestion de la configuration
安装Oracle EE
Flink面试题
C language student information management system
电视机尺寸与观看距离
FAQ | FAQ for building applications for large screen devices
Football and basketball game score live broadcast platform source code /app development and construction project
FreeRTOS learning easy notes
猿人学第20题(题目会不定时更新)
Shell script -if else statement
How to solve the problem of fixed assets management and inventory?
Yolov3, 4, 5 and 6 Summary of target detection
Shell脚本-for循环和for int循环
Shell脚本-位置参数(命令行参数)
动态代理
Matlab tips (23) matrix analysis -- simulated annealing
How to effectively align team cognition