当前位置:网站首页>leetcode-540. A single element in an ordered array
leetcode-540. A single element in an ordered array
2022-07-03 20:49:00 【Eager to be the winner of loneliness】
- 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
Tips :
1 <= nums.length <= 105
0 <= nums[i] <= 105
class Solution {
public int singleNonDuplicate(int[] nums) {
int min=0,max=nums.length-1;
while(min<max){
int mid=(min+max)/2; // Or written (max-min)/2+min
if(nums[mid]==nums[mid^1]){
// Be careful : Here is bitwise XOR
min=mid+1;
}
else{
max=mid;
}
}
return nums[min];
}
}
边栏推荐
- 2022 low voltage electrician examination and low voltage electrician simulation examination question bank
- Global and Chinese market of full authority digital engine control (FADEC) 2022-2028: Research Report on technology, participants, trends, market size and share
- The 12th Blue Bridge Cup
- AST (Abstract Syntax Tree)
- thrift go
- 【leetcode】1027. Longest arithmetic sequence (dynamic programming)
- Shortest path problem of graph theory (acwing template)
- University of Electronic Science and technology | playback of clustering experience effectively used in reinforcement learning
- JS three families
- C 10 new feature [caller parameter expression] solves my confusion seven years ago
猜你喜欢

强化學習-學習筆記1 | 基礎概念

2022 melting welding and thermal cutting examination materials and free melting welding and thermal cutting examination questions

It is discussed that the success of Vit lies not in attention. Shiftvit uses the precision of swing transformer to outperform the speed of RESNET

Scientific research document management Zotero
![AI enhanced safety monitoring project [with detailed code]](/img/a9/cb93f349229e86cbb05ad196ae9553.jpg)
AI enhanced safety monitoring project [with detailed code]

thrift go

《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!...

From the behind the scenes arena of the ice and snow event, see how digital builders can ensure large-scale events

Gee calculated area

Interval product of zhinai sauce (prefix product + inverse element)
随机推荐
Viewing Chinese science and technology from the Winter Olympics (II): when snowmaking breakthrough is in progress
Node MySQL serialize cannot rollback transactions
Rhcsa third day operation
Transformer structure analysis and the principle of blocks in it
Rhcsa third day notes
你真的知道自己多大了吗?
SQL injection - Fundamentals of SQL database operation
Reinforcement learning - learning notes 1 | basic concepts
Cap and base theory
19、 MySQL -- SQL statements and queries
Do you really know how old you are?
The global industrial design revenue in 2021 was about $44360 million, and it is expected to reach $62720 million in 2028. From 2022 to 2028, the CAGR was 5.5%
淺析 Ref-NeRF
Global and Chinese markets of cast iron diaphragm valves 2022-2028: Research Report on technology, participants, trends, market size and share
Hcie security Day12: supplement the concept of packet filtering and security policy
Assign the CMD command execution result to a variable
Global and Chinese markets of active matrix LCD 2022-2028: Research Report on technology, participants, trends, market size and share
2.6 formula calculation
In 2021, the global revenue of thick film resistors was about $1537.3 million, and it is expected to reach $2118.7 million in 2028
2.4 conversion of different data types