Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
CompareVersion Solution Added
  • Loading branch information
Deeeeksha committed Jan 10, 2022
commit 9a7ae2af4f1534b5b75291660648ae0413168047
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)