当前位置:网站首页>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;
}
边栏推荐
- Notice on Soliciting Opinions on the draft of information security technology mobile Internet application (APP) life cycle security management guide
- Avoid playing with super high conversion rate in material minefields
- Pratique technique | analyse et solution des défaillances en ligne (Partie 1)
- Use classname to modify style properties
- C import Xls data method summary III (processing data in datatable)
- Skku| autonomous handover decision of UAV Based on deep reinforcement learning
- Magical usage of edge browser (highly recommended by program ape and student party)
- 0 basic learning C language - nixie tube dynamic scanning display
- Ka! Why does the seat belt suddenly fail to pull? After reading these pictures, I can't stop wearing them
- “疫”起坚守 保障数据中台服务“不打烊”
猜你喜欢
Huawei BFD and NQA
“疫”起坚守 保障数据中台服务“不打烊”
SQL statement
String hash, find the string hash value after deleting any character, double hash
Infiltration learning diary day19
Pratique technique | analyse et solution des défaillances en ligne (Partie 1)
Small program graduation project based on wechat examination small program graduation project opening report function reference
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
Avoid playing with super high conversion rate in material minefields
Feign implements dynamic URL
随机推荐
Cesiumjs 2022^ source code interpretation [8] - resource encapsulation and multithreading
be based on. NETCORE development blog project starblog - (14) realize theme switching function
CLP information - how does the digital transformation of credit business change from star to finger?
[turn] solve the problem of "RSA public key not find" appearing in Navicat premium 15 registration
Fundamentals of machine learning: feature selection with lasso
MySQL uses the view to report an error, explain/show can not be issued; lacking privileges for underlying table
【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
Make drop-down menu
Jerry's watch information type table [chapter]
Hash table, string hash (special KMP)
Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference
Jerry's synchronous weather information to equipment [chapter]
7.1 learning content
Conditional statements of shell programming
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
Pyinstaller packaging py script warning:lib not found and other related issues
Portable two-way radio equipment - current market situation and future development trend
技术实践|线上故障分析及解决方法(上)
Audio resource settings for U3D resource management
C import Xls data method summary V (complete code)