当前位置:网站首页>2022.02.14 - 239. A single element in an ordered array
2022.02.14 - 239. A single element in an ordered array
2022-06-29 06:15:00 【A CAI continues to work hard】
List of articles
1. subject

2. Ideas
(1) Two points search
- In an array where elements appear in pairs , The first subscript of each pair of elements is an even number , The second subscript is odd .
- When the middle subscript is an even number , If this element is equal to the next element , It means that the previous elements appear in pairs ; When the middle subscript is an odd number , If this element is equal to the previous element , It means that the previous elements appear in pairs .
3. Code
public class Test {
public static void main(String[] args) {
}
}
class Solution {
public int singleNonDuplicate(int[] nums) {
int left = 0;
int right = nums.length - 1;
while (left < right) {
int mid = left + ((right - left) >> 1);
if ((mid & 1) == 0) {
if (nums[mid] == nums[mid + 1]) {
left = mid + 1;
} else {
right = mid;
}
} else {
if (nums[mid] == nums[mid - 1]) {
left = mid + 1;
} else {
right = mid;
}
}
}
return nums[left];
}
}
边栏推荐
- Alphacode made its debut! The programming version of "Alpha dog" competed quietly and defeated half of the programmers
- Quickly write MVVM code using source generators
- Hyperledger Fabric 2. X custom smart contract
- Fault: KDC warning log for id29
- ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers
- Review of MySQL knowledge points
- HTTP Caching Protocol practice
- CodeIgniter active record not equal - CodeIgniter active record not equal
- Week 10 - task 3- from point to circle to cylinder
- 5,10-di (4-aminophenyl) - 15,20-diphenylporphyrin (cis-dadph2) /5,15-di (4-aminophenyl) - 10,20-diphenylporphyrin (trans-dadph2) / (tri-apph2) supplied by Qiyue
猜你喜欢

Call the computer calculator and use it to convert several base numbers

Why can't the article be posted?

Design and practice of kubernetes cluster and application monitoring scheme

51 single chip microcomputer learning notes 7 -- Ultrasonic Ranging

2022 recommended trend toy blind box industry research report industry development prospect market analysis white paper (the attachment is a link to the network disk, and the report is continuously up

2,5-di (3,4-dicarboxyphenoxy) - 4 '- phenylethynylbiphenyldianhydride (pephqda) / Qiyue custom supply porphyrin modified amphiphilic block copolymer peg113-pcl46-porphyrin

Difference between URI and URL

What are the uses of wireless pressure collectors?
![Meso tetra (4-N, N, n-trimethylaminophenyl) porphyrin (ttmapp) /meso tetra - [4- (BOC threonine) aminophenyl] porphyrin (TAPP thr BOC) supplied by Qiyue](/img/a9/0869c4f39a96cff63d1e310292c46d.jpg)
Meso tetra (4-N, N, n-trimethylaminophenyl) porphyrin (ttmapp) /meso tetra - [4- (BOC threonine) aminophenyl] porphyrin (TAPP thr BOC) supplied by Qiyue

Analysis report on the investment market of the development planning prospect of the recommended wind power industry research industry in 2022 (the attachment is a link to the network disk, and the re
随机推荐
Week 10 - task 3- from point to circle to cylinder
How to insert pseudo code into word documents simply and quickly?
Benign competition will promote each other
Skills of writing test cases efficiently
Fault: KDC warning log for id29
2022 community group buying industry research industry development planning prospect investment market analysis report (the attachment is the online disk link, and the report is continuously updated)
2022.02.14
Ctrip launched the "3+2" office mode. Are you sour?
Why Houdini made the pyside2 plug-in crash
Meso tetra (4-N, N, n-trimethylaminophenyl) porphyrin (ttmapp) /meso tetra - [4- (BOC threonine) aminophenyl] porphyrin (TAPP thr BOC) supplied by Qiyue
Activiti Designer
Manual (functional) test 1
Honeypot based on MySQL load data local INFILE
VLAN experiment
Spark saving to external data source
51 lines of code, self-made TX to MySQL software!
Week 12 - task 2- shoulder to shoulder cadres
Top ten Devops best practices worthy of attention in 2022
Servlet version conflict causes page 404
Hyperledger Fabric 2. X custom smart contract