Python: O(n) solution in 12 lines!


#1
def compareVersion(self, A, B):
    A = list(map(int, A.split('.')))
    B = list(map(int, B.split('.')))
    while (len(A)<len(B)):
        A.append(0);
    while (len(B)<len(A)):
        B.append(0)
    for i in range(len(A)):
        if A[i]<B[i]:
            return -1
        if B[i]<A[i]:
            return 1
    return 0