当传入 [1,1,1,0,1,1,1,1] 和 2 days 的时候给预期答案是返回 [0,0,0,0,0,1,1,0], 但是我算出来不应该返回 [0,1,0,0,0,1,0,0] 才对吗?是我理解错了吗?
1
ConradG 2020-05-03 02:17:36 +08:00
[1, 0, 1] --> [x, 1, y]
|
2
sneezry 2020-05-03 02:19:55 +08:00
day 0: 1,1,1,0,1,1,1,1
day 1: 1,0,1,0,1,0,0,1 day 2: 0,0,0,0,0,1,1,0 var preArr, arr = [1,1,1,0,1,1,1,1]; var day = 2; while(day--) { preArr = arr; arr = []; for (let i = 0; i < preArr.length; i++) { let left = i > 0 ? preArr[i - 1] : 0; let right = i < preArr.length - 1 ? preArr [i + 1] : 0; arr[i] = left ^ right; } } console.log(arr) |
5
Mirage09 2020-05-03 07:08:31 +08:00 via iPhone
|