Codility 解决方案 [Swift 3.0]

[Codility] Lession 2.2 OddOccurr

2016-07-20  本文已影响257人  sunlitamo

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
}
上一篇 下一篇

猜你喜欢

热点阅读