Created
May 4, 2016 22:11
-
-
Save vikmeup/9285ec972ae7b60e20b1f8cf9b27548a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
func compareVersion(version1: String, _ version2: String) -> Int { | |
var v1 = version1.characters.split(".").map { Int(String($0)) } | |
var v2 = version2.characters.split(".").map { Int(String($0)) } | |
var result = 0 | |
for i in 0..<max(v1.count,v2.count) { | |
let left = i >= v1.count ? 0 : v1[i] | |
let right = i >= v2.count ? 0 : v2[i] | |
if (left == right) { | |
result = 0 | |
} else if left > right { | |
return 1 | |
} else if right > left { | |
return -1 | |
} | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
current.compare(appStore, options: .numeric)