Single Number

This is an easy but very tricky problem specially if you aren’t too familiar with logical operations.

class Solution {
    fun singleNumber(nums: IntArray): Int {
        var answer = nums[0]
        (1 until nums.size).forEach {answer = answer xor nums[it]}
        return answer
    }
}
Runtime: 196 ms, faster than 73.04% of Kotlin online submissions for Single Number.
Memory Usage: 36.3 MB, less than 100.00% of Kotlin online submissions for Single Number.