当前位置:网站首页>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];
}
}
边栏推荐
- Regular expressions for shell script values
- How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
- CodeIgniter active record not equal - CodeIgniter active record not equal
- Personal blog item: processing of reading number +1 after viewing article details
- Call the computer calculator and use it to convert several base numbers
- Two houses with different colors and the farthest distance
- 2022.02.14
- Meso tetra (4-N, N, n-trimethylaminophenyl) porphyrin (ttmapp) /meso tetra - [4- (BOC threonine) aminophenyl] porphyrin (TAPP thr BOC) supplied by Qiyue
- Will the order of where conditions in MySQL affect the union index? Will where 1 =1 affect the use of the index? Does where 1 =1 affect the use of indexes?
- Can I cast int to a variable of type byte? What happens if the value is larger than the range of byte type?
猜你喜欢

Alphacode made its debut! The programming version of "Alpha dog" competed quietly and defeated half of the programmers

What is the "danksharding" of V God Kop on Valentine's day?
![[C language series] - initial C language (4)](/img/3b/b20d6e0194f2114f8c27a17d58369a.jpg)
[C language series] - initial C language (4)

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)

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

Difference between parametric continuity and geometric continuity

Research Report on the recommended lithography industry in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report is continuously u

The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers

What has urbanization brought to our mental health and behavior?
![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
随机推荐
MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
Can use the mouse, will reinstall the computer system tutorial sharing
Creation of Arduino uno development environment
P5 DS - component and document Association
Ti Click: quickly set up tidb online laboratory through browser | ti- team interview can be conducted immediately
Leetcode theme [array] -217- there are duplicate elements
Difference between parametric continuity and geometric continuity
Devops development, operation and maintenance Basics: using Jenkins to automatically build projects and notify by email
Installing modules in pycharm
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
Go compile source code (window environment)
Mongodb sort function
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
Establishing the development environment of esp8266
Rich material libraries make modeling easy and efficient for developers
How to hand over complex legacy systems?
Multiline regular expression search in Visual Studio code - multiline regular expression search in Visual Studio code
Fault: ntfrs warning log for id13562
The generation of leetcode simple questions each character is an odd number of strings
2022 recommended prefabricated construction industry research report industry development prospect market analysis white paper (the attachment is a link to the network disk, and the report is continuo