Skip to content

Commit 131e115

Browse files
committed
22w9: 剑指 Offer 53 - II. 0~n-1中缺失的数字
1 parent f0f67db commit 131e115

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,8 @@
450450
| # | Title | Solution | Difficulty |
451451
|---| ----- | -------- | ---------- |
452452
|面试题 08.06|[汉诺塔问题](https://leetcode-cn.com/problems/hanota-lcci/) | [js](./algorithms/hanotaLcc/hanotaLcc.js) |Easy|
453+
454+
## 剑指 Offer
455+
| # | Title | Solution | Difficulty |
456+
|---| ----- | -------- | ---------- |
457+
|53 - II|[0~n-1中缺失的数字](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/) | [js](./algorithms/queShiDeShuZiLcof/solution.js) |Easy|
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var missingNumber = function(nums) {
6+
let result = 0;
7+
// XOR of all values in the given array
8+
for (let i = 0; i < nums.length; i++) {
9+
result ^= nums[i]
10+
}
11+
// XOR of all the values from 0 to length of array
12+
for (let i = 0; i <= nums.length; i++) {
13+
result ^= i;
14+
}
15+
return result;
16+
};

0 commit comments

Comments
 (0)