Simple python solution, easy to understand


#1

class Solution:
# @param A : string
# @param B : string
# @return an integer
def compareVersion(self, A, B):
l1=A.split(".")
l2=B.split(".")
a=len(l1)
b=len(l2)
if(a<b):
s=a
else:
s=b
flag=0
for i in range(s):
if(int(l1[i],10)>int(l2[i],10)):
flag=1
break
if(int(l1[i],10)<int(l2[i],10)):
flag=-1
break
if(flag!=0):
return flag
else:
if(flag==0 and a==b):
return 0
else:
sum1=0
sum2=0
for i in l1:
sum1+=int(i,10)
for i in l2:
sum2+=int(i,10)
if(sum1==sum2):
return 0
if(a<b):
return -1
else:
return 1