Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompareVersion Solution Added #50

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions python/165_Compare_Version_Numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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)