Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf119d27

Browse files
MEDIUM/src/medium/MissingNumber.java
1 parentbddcebe commitf119d27

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎MEDIUM/src/medium/MissingNumber.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
packagemedium;
2+
3+
publicclassMissingNumber {
4+
//This post has a very good explanation: https://discuss.leetcode.com/topic/24535/4-line-simple-java-bit-manipulate-solution-with-explaination
5+
//we can simply XOR with the indices of the array since XOR twice the same number will become zero
6+
publicintmissingNumber(int[]nums) {
7+
intxor =0,i =0;
8+
for(;i <nums.length;i++){
9+
xor =xor^i^nums[i];
10+
}
11+
returnxor^i;
12+
}
13+
14+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp