g0101_0200.s0137_single_number_ii.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
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
}
}