Skip to content

Instantly share code, notes, and snippets.

@vikmeup
Created May 4, 2016 22:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vikmeup/9285ec972ae7b60e20b1f8cf9b27548a to your computer and use it in GitHub Desktop.
Save vikmeup/9285ec972ae7b60e20b1f8cf9b27548a to your computer and use it in GitHub Desktop.
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
}
}
@alkozin
Copy link

alkozin commented Oct 17, 2019

current.compare(appStore, options: .numeric)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment