当前位置:网站首页>540. Single element in ordered array
540. Single element in ordered array
2022-07-01 18:17:00 【Listen 1024】
>540. A single element in an ordered array <
>singleNonDuplicate<
One 、 Their thinking
1、 Solution 1 ( Java )
Solution ideas : XOR pairing + Two points search
adopt An operation
Medium mid ^ 1
Exclusive or
Operator to unify parity
- i For even when :
i ^ 1 == i + 1
, The result is the odd number after the original even number plus one - i In an odd number of :
i ^ 1 == i - 1
, The result is the even number after subtracting one from the original odd number
/** * @author listen1024 * @date 2022-2-14 * 540. A single element in an ordered array */
class Solution {
public int singleNonDuplicate(int[] nums) {
int low = 0;
int high = nums.length - 1;
while (low < high) {
int mid = (low + high) /2;
if (nums[mid] == nums[mid ^ 1]){
low = mid + 1;
} else {
high = mid;
}
}
return nums[low];
}
}
The screenshot of the running result is as follows :
边栏推荐
- Slider verification code identification gadget display
- Good looking UI mall source code has been scanned, no back door, no encryption
- Equipment simulation and deduction training system software
- Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
- Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
- Product service, operation characteristics
- Kernel stray cat stray dog pet adoption platform H5 source code
- MySQL -- explain performance optimization
- Bug of QQ browser article comment: the commentator is wrong
- Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
猜你喜欢
Flex layout
From comedians to NBA Zhan Huang, check the encrypted advertisements during this super bowl
What are the legal risks of NFT brought by stars such as curry and O'Neill?
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
Yolov5 practice: teach object detection by hand
How to write good code - Defensive Programming Guide
Enter wechat applet
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Petrv2: a unified framework for 3D perception of multi camera images
Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
随机推荐
Data warehouse (3) star model and dimension modeling of data warehouse modeling
Work and leisure suggestions of old programmers
On the language internationalization of Yongzhong Office
Redis -- data type and operation
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
Fix the problem that easycvr device video cannot be played
JDBC: deep understanding of Preparedstatement and statement[easy to understand]
PHP implements sensitive word filtering system "suggestions collection"
Petrv2: a unified framework for 3D perception of multi camera images
How to retrieve the password for opening Excel files
[C supplement] [string] display the schedule of a month by date
Explain in detail the process of realizing Chinese text classification by CNN
证券开户安全么,有没有什么样的危险呢
Mujoco's biped robot Darwin model
传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
Develop those things: add playback address authentication to easycvr platform
transform. Forward and vector3 Differences in the use of forward
Convert the robot's URDF file to mujoco model
Mujoco model learning record
Key points on February 15, 2022