美文网首页Codility 解决方案 [Swift 3.0]
[Codility] Lession 2.2 OddOccurr

[Codility] Lession 2.2 OddOccurr

作者: sunlitamo | 来源:发表于2016-07-20 19:22 被阅读257次

Swift Solution:

public func solution(inout A : [Int]) -> Int {
   // Return itself if array only contains 1 element
   if (A.count == 1) { return A[0] }
   var oe = 0
   //Since only one odd integer in the array 
   //so using Xor will balance all the pair numbers except the odd integer
   for i in 0 ..< A.count { oe ^= A[i] }
   return oe
}

相关文章

网友评论

    本文标题:[Codility] Lession 2.2 OddOccurr

    本文链接:https://www.haomeiwen.com/subject/qynvjttx.html