Skip to content

Commit 9f9fb42

Browse files
authored
Create 1486-xor-operation-in-an-array.js
1 parent b19d5f1 commit 9f9fb42

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

1486-xor-operation-in-an-array.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number} n
3+
* @param {number} start
4+
* @return {number}
5+
*/
6+
const xorOperation = function(n, start) {
7+
const nums = []
8+
let i = 0
9+
while (i < n) {
10+
nums[i] = start + 2 * i
11+
i++
12+
}
13+
// console.log(nums)
14+
let res = nums[0]
15+
for(let i = 1; i < n; i++) res ^= nums[i]
16+
return res
17+
};

0 commit comments

Comments
 (0)