当前位置:网站首页>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 !
边栏推荐
- Nacos - 服务发现
- Log4j 日志框架
- Ape anthropology topic 20 (the topic will be updated from time to time)
- Memory size end
- Understanding and implementation of AVL tree
- Input标签的type设置为number,去掉上下箭头
- Redis -- lattice connects to redis cluster
- 易点易动助力企业设备高效管理,提升设备利用率
- Nacos - Configuration Management
- Shell脚本-read命令:读取从键盘输入的数据
猜你喜欢
VSYNC+三重缓存机制+Choreographer
【MFC开发(17)】高级列表控件List Control
Dynamic proxy
Computer tips
3. Detailed explanation of Modbus communication protocol
小鸟识别APP
Principle and application of single chip microcomputer timer, serial communication and interrupt system
Nacos - 服务发现
5mo3 UHI HII HII 17mn4 19Mn6 executive standard
Pain points and solutions of equipment management in large factories
随机推荐
【MFC开发(16)】树形控件Tree Control
Differences among tasks, threads and processes
The fixed assets management system enables enterprises to dynamically master assets
VSYNC+三重缓存机制+Choreographer
What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?
Jeecg restart alarm 40001
Shell script - array definition and getting array elements
中考体育项目满分标准(深圳、安徽、湖北)
Meituan machine test in 2022
Nacos - service discovery
C language student information management system
IT 技术电子书 收藏
易点易动助力企业设备高效管理,提升设备利用率
Mysql8.0 learning record 17 -create table
In depth learning training sample amplification and tag name modification
"Analysis of 43 cases of MATLAB neural network": Chapter 30 design of combined classifier based on random forest idea - breast cancer diagnosis
钓鱼识别app
如何解决固定资产管理和盘点的难题?
通过 代码实例 理解 浅复制 与 深复制
Shell script -if else statement