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 1 commit
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
30 changes: 30 additions & 0 deletions python/165_CompareVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution:
def CompareVersion(self, version1: str, version2: str) -> int:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to compareVersion to avoid submission error

l1=list(map(int,version1.split('.')))
l2=list(map(int,version2.split('.')))
#print(l1,l2)
if l1==l2:
return(0)

a=len(l1)
b=len(l2)

if a>b:
for i in range(a-b):
l2.append("0")

if b>a:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if can be change to 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)