My AC python code


  • 0
    S

    class Solution:
    # @param a, a string
    # @param b, a string
    # @return a boolean
    def compareVersion(self, version1, version2):
    return self.solve(version1, version2)

    def solve(self, v1, v2):
        p1, p2 = 0, 0
        while p1 < len(v1) or p2 < len(v2):
            t1 = 0
            if p1 < len(v1):
                q1 = v1.find('.', p1)
                if q1 == -1:
                    q1 = len(v1)
                t1 = int(v1[p1:q1])
                p1 = q1 + 1
            t2 = 0
            if p2 < len(v2):
                q2 = v2.find('.', p2)
                if q2 == -1:
                    q2 = len(v2)
                t2 = int(v2[p2:q2])
                p2 = q2 + 1
            if t1 < t2:
                return -1
            elif t1 > t2:
                return 1
        return 0

Log in to reply
 

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