-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path165.py
31 lines (30 loc) · 943 Bytes
/
165.py
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
27
28
29
30
31
# https://leetcode.com/problems/compare-version-numbers/
class Solution(object):
def compareVersion(self, version1, version2):
"""
:type version1: str
:type version2: str
:rtype: int
"""
v1 = version1.split('.')
v2 = version2.split('.')
cur = 0
len1 = len(v1)
len2 = len(v2)
while True:
if cur >= len1 and cur >= len2:
return 0
elif cur >= len1 and int(v2[cur]) != 0:
return -1
elif cur >= len2 and int(v1[cur]) != 0:
return 1
elif cur >= len1 or cur >= len2:
cur += 1
else:
if int(v1[cur]) > int(v2[cur]):
return 1
elif int(v1[cur]) < int(v2[cur]):
return -1
else:
cur += 1
#print Solution().compareVersion('0', '1')