当前位置:网站首页>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;
}
边栏推荐
- Summary of common tools and technical points of PMP examination
- MySQL uses the view to report an error, explain/show can not be issued; lacking privileges for underlying table
- Description of setting items of Jerry [chapter]
- Conditional test, if, case conditional test statements of shell script
- Jerry's synchronous weather information to equipment [chapter]
- MySQL statement learning record
- Huawei rip and BFD linkage
- Jerry's modification setting status [chapter]
- MySQL - use of aggregate functions and group by groups
- Douban scoring applet Part-3
猜你喜欢
Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]
Huawei cloud micro certification Huawei cloud computing service practice has been stable
Remember a lazy query error
Make drop-down menu
Openbionics exoskeleton project introduction | bciduino community finishing
Long article review: entropy, free energy, symmetry and dynamics in the brain
ES6 deletes an attribute in all array objects through map, deconstruction and extension operators
How to delete MySQL components using xshell7?
GUI application: socket network chat room
技術實踐|線上故障分析及解决方法(上)
随机推荐
Day05 table
Portable two-way radio equipment - current market situation and future development trend
7.1 learning content
Technical practice online fault analysis and solutions (Part 1)
MySQL deadly serial question 2 -- are you familiar with MySQL index?
AI helps make new breakthroughs in art design plagiarism retrieval! Professor Liu Fang's team paper was employed by ACM mm, a multimedia top-level conference
What are the advantages and disadvantages of data center agents?
Remember a lazy query error
Query efficiency increased by 10 times! Three optimization schemes to help you solve the deep paging problem of MySQL
Description of setting items of Jerry [chapter]
Douban scoring applet Part-3
Which insurance products can the elderly buy?
Pyinstaller packaging py script warning:lib not found and other related issues
Is Shengang securities company as safe as other securities companies
Who moved my code!
C import Xls data method summary III (processing data in datatable)
查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题
Notice on Soliciting Opinions on the draft of information security technology mobile Internet application (APP) life cycle security management guide
Huawei cloud micro certification Huawei cloud computing service practice has been stable
I don't know why it can't run in the project and how to change it