class Solution:
# @param A : string
# @param B : string
# @return an integer
def compareVersion(self, A, B):
vera = list(map(int, A.split('.')))
verb = list(map(int, B.split('.')))
for ind in range(max(len(vera), len(verb))):
anum = vera[ind] if ind < len(vera) else 0
bnum = verb[ind] if ind < len(verb) else 0
if anum < bnum:
return -1
elif anum > bnum:
return 1
return 0
I have splitted the numbers along the dots and then kept comparing the corresponding digits in the version numbers. If the corres number doesn’t exist (in case the length of one version is more than other) I assume the missing one to be zero.