-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCompareVersionNumber.py
More file actions
26 lines (24 loc) · 861 Bytes
/
CompareVersionNumber.py
File metadata and controls
26 lines (24 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 165. Compare Version Number
class Solution:
def compareVersion(self, version1, version2):
"""
:type version1: str
:type version2: str
:rtype: int
"""
version1 = list(map(lambda x:int(x), version1.split(".")))
version2 = list(map(lambda x:int(x), version2.split(".")))
n = min(len(version1), len(version2))
for i in range(n):
if int(version1[i]) == int(version2[i]):
continue
elif int(version1[i]) > int(version2[i]):
return 1
else:
return -1
if len(version1) > len(version2) and version1[n:] != [0] * (len(version1) - n):
return 1
elif len(version1) < len(version2) and version2[n:] != [0] * (len(version2) - n):
return -1
else:
return 0