Python O(n) time solution 36ms 91%


  • 2
    D
    class Solution(object):
        def compareVersion(self, version1, version2):
            """
            :type version1: str
            :type version2: str
            :rtype: int
            """
            v1 = map(int,version1.split("."))
            v2 = map(int,version2.split("."))
            if len(v1) < len(v2):
                v1.extend([0]*(len(v2)-len(v1)))
            else:
                v2.extend([0]*(len(v1)-len(v2)))
            return cmp(v1,v2)

Log in to reply
 

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