All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0101_0200.s0137_single_number_ii.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g0101_0200.s0137_single_number_ii

// #Medium #Array #Bit_Manipulation #2022_10_09_Time_344_ms_(64.29%)_Space_38.4_MB_(92.86%)

class Solution {
    fun singleNumber(nums: IntArray): Int {
        var ones = 0
        var twos = 0
        for (num in nums) {
            ones = ones xor num and twos.inv()
            twos = twos xor num and ones.inv()
        }
        return ones
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy