Skip to content

Commit 76137fa

Browse files
authored
Add 165_Compare_Version_Numbers (qiyuangong#50)
* 165 CompareVersion Solution Contributed by @Deeeeksha
1 parent 790f9ee commit 76137fa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

python/165_Compare_Version_Numbers.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
def compareVersion(self, version1: str, version2: str) -> int:
3+
l1=list(map(int,version1.split('.')))
4+
l2=list(map(int,version2.split('.')))
5+
if l1==l2:
6+
return(0)
7+
8+
a=len(l1)
9+
b=len(l2)
10+
11+
if a>b:
12+
for i in range(a-b):
13+
l2.append("0")
14+
15+
else:
16+
for i in range(b-a):
17+
l1.append("0")
18+
19+
for i in range(len(l1)):
20+
if int(l1[i])>int(l2[i]):
21+
return(1)
22+
23+
elif int(l1[i])<int(l2[i]):
24+
return(-1)
25+
26+
else:
27+
pass
28+
29+
return(0)

0 commit comments

Comments
 (0)