4 LINE PYTHON CODE


  • 1
    R
    class Solution(object):
        def compareVersion(self, version1, version2):
            """
            :type version1: str
            :type version2: str
            :rtype: int
            """
            version1, version2 = list(map(int,version1.split('.'))), list(map(int, version2.split('.')))
            sum1 = sum( [ version1[i]*(10**(-i)) for i in range(len(version1)) ] )
            sum2 = sum( [ version2[i]*(10**(-i)) for i in range(len(version2)) ] )
            return int((sum1-sum2)/abs(sum1-sum2)) if sum1 - sum2 != 0 else 0
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.