LeetCode 165 Compare Version Numbers

LeetCode 165 Compare Version Numbers Problem

Download Code
class Solution:
    def compareVersion(self, version1: str, version2: str) -> int:
        l1=list(map(int,version1.split('.')))
        l2=list(map(int,version2.split('.')))
        if l1==l2:
            return(0)
        
        a=len(l1)
        b=len(l2)
        
        if a>b:
            for i in range(a-b):
                l2.append("0")
        
        else:
            for i in range(b-a):
                l1.append("0")
            
        for i in range(len(l1)):
            if int(l1[i])>int(l2[i]):
                return(1)
            
            elif int(l1[i])<int(l2[i]):
                return(-1)
            
            else:
                pass
        
        return(0)
Download Compare Version Numbers.py

List of all Compare Version Numbers problems

Leetcode 165 Compare Version Numbers problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.