当前位置:网站首页>Winter vacation daily question -- a single element in an ordered array
Winter vacation daily question -- a single element in an ordered array
2022-07-04 01:40:00 【A cat that doesn't eat mice】
- Topic link :https://leetcode-cn.com/problems/single-element-in-a-sorted-array/
- Title Description
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 .
- Example
Input : nums = [1,1,2,3,3,4,4,8,8]
Output : 2
Ideas
Using the properties of XOR .
0 ⊕ n = n 0 And n XOR equals n
n ⊕ n = 0 The XOR operation of any two identical numbers equals 0
- Code
public int singleNonDuplicate(int[] nums) {
int num = 0;
for(int i : nums)
num ^= i;
return num;
}
边栏推荐
- Make drop-down menu
- Audio resource settings for U3D resource management
- Introduction to superresolution
- Huawei rip and BFD linkage
- Gnupg website
- 51 single chip microcomputer timer 2 is used as serial port
- Decompile and modify the non source exe or DLL with dnspy
- Ka! Why does the seat belt suddenly fail to pull? After reading these pictures, I can't stop wearing them
- Future source code view -juc series
- In the process of seeking human intelligent AI, meta bet on self supervised learning
猜你喜欢
Luogu p1309 Swiss wheel
MySQL deadly serial question 2 -- are you familiar with MySQL index?
After listening to the system clear message notification, Jerry informed the device side to delete the message [article]
Three layer switching ①
Jerry's modification setting status [chapter]
I don't care about you. OKR or KPI, PPT is easy for you
MPLS③
Huawei cloud micro certification Huawei cloud computing service practice has been stable
C import Xls data method summary II (save the uploaded file to the DataTable instance object)
Since the "epidemic", we have adhered to the "no closing" of data middle office services
随机推荐
2022 R2 mobile pressure vessel filling certificate examination and R2 mobile pressure vessel filling simulation examination questions
Force deduction solution summary 1189- maximum number of "balloons"
The force deduction method summarizes the single elements in the 540 ordered array
Which insurance products can the elderly buy?
Small program graduation project based on wechat reservation small program graduation project opening report reference
Msp32c3 board connection MSSQL method
Setting function of Jerry's watch management device [chapter]
Small program graduation project based on wechat examination small program graduation project opening report function reference
Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference
Ka! Why does the seat belt suddenly fail to pull? After reading these pictures, I can't stop wearing them
Jerry's synchronous weather information to equipment [chapter]
Since the "epidemic", we have adhered to the "no closing" of data middle office services
Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
ES6 deletes an attribute in all array objects through map, deconstruction and extension operators
机器学习基础:用 Lasso 做特征选择
Cesiumjs 2022^ source code interpretation [8] - resource encapsulation and multithreading
Long article review: entropy, free energy, symmetry and dynamics in the brain
Is Shengang securities company as safe as other securities companies
Maximum entropy model
Software product download collection