当前位置:网站首页>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 !
边栏推荐
- Redis源码学习(29),压缩列表学习,ziplist.c(二)
- 【MFC开发(17)】高级列表控件List Control
- Shell script - array definition and getting array elements
- Microcomputer principle - bus and its formation
- Pain points and solutions of equipment management in large factories
- Meituan machine test in 2022
- Nacos - Configuration Management
- Insert mathematical formula in MD document and mathematical formula in typora
- MySQL optimization
- I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?
猜你喜欢

TV size and viewing distance

3. Detailed explanation of Modbus communication protocol

Vsync+ triple cache mechanism +choreographer

集团公司固定资产管理的痛点和解决方案

如何做好固定资产管理?易点易动提供智能化方案

Redis -- lattice connects to redis cluster
![[MFC development (16)] tree control](/img/b9/1de4330c0bd186cfe062b02478c058.png)
[MFC development (16)] tree control

How to manage fixed assets efficiently in one stop?

Understanding and implementation of AVL tree

FreeRTOS learning easy notes
随机推荐
小鸟识别APP
Embedded Engineer Interview frequently asked questions
Input标签的type设置为number,去掉上下箭头
Databinding source code analysis
Football and basketball game score live broadcast platform source code /app development and construction project
JCL 和 SLF4J
Shell脚本-read命令:读取从键盘输入的数据
Shell script - positional parameters (command line parameters)
C language student information management system
Bimianhongfu queren()
Guidelines and principles of did
Serialization, listening, custom annotation
LogBack
R language observation log (part24) -- initialization settings
Shell脚本-位置参数(命令行参数)
Shell script -read command: read data entered from the keyboard
pcl_ Viewer command
VSYNC+三重缓存机制+Choreographer
Shell脚本-while循环详解
猿人学第20题(题目会不定时更新)