Kotlin Leetcode - 1486. XOR Operation in an Array
題目連接:https://leetcode.com/problems/xor-operation-in-an-array/
class Solution {
fun xorOperation(n: Int, start: Int): Int {
}
}
解題思路
這一題考的是陣列內 xor
處理
Kotlin 參考解答
單一表達式的解法如下
class Solution {
fun xorOperation(n: Int, start: Int) =
List(n) { start + 2 * it }
.foldRight(0) { acc, c -> acc xor c }
}
回到 leetcode 列表