当前位置:网站首页>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;
}
边栏推荐
- Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
- Make drop-down menu
- Force deduction solution summary 1189- maximum number of "balloons"
- Conditional statements of shell programming
- All metal crowns - current market situation and future development trend
- MySQL statement learning record
- 中电资讯-信贷业务数字化转型如何从星空到指尖?
- Small program graduation project based on wechat video broadcast small program graduation project opening report function reference
- Solution to the problem that jsp language cannot be recognized in idea
- Why can't it run (unresolved)
猜你喜欢

“疫”起坚守 保障数据中台服务“不打烊”

技术实践|线上故障分析及解决方法(上)

Since the "epidemic", we have adhered to the "no closing" of data middle office services

Long article review: entropy, free energy, symmetry and dynamics in the brain

IPv6 experiment

C import Xls data method summary II (save the uploaded file to the DataTable instance object)

CLP information - how does the digital transformation of credit business change from star to finger?

MySQL statement learning record

Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?

Who moved my code!
随机推荐
Douban scoring applet Part-3
be based on. NETCORE development blog project starblog - (14) realize theme switching function
Customize redistemplate tool class
ES6 deletes an attribute in all array objects through map, deconstruction and extension operators
I don't care about you. OKR or KPI, PPT is easy for you
Day05 table
Install the pit that the electron has stepped on
IPv6 experiment
Technical practice online fault analysis and solutions (Part 1)
中电资讯-信贷业务数字化转型如何从星空到指尖?
GUI application: socket network chat room
MySQL introduction - functions (various function statistics, exercises, details, tables)
How can enterprises optimize the best cost of cloud computing?
Pyrethroid pesticide intermediates - market status and future development trend
Fundamentals of machine learning: feature selection with lasso
Portable two-way radio equipment - current market situation and future development trend
Small program graduation project based on wechat examination small program graduation project opening report function reference
Do you know the eight signs of a team becoming agile?
Three layer switching ②
Flex flexible layout, box in the middle of the page