We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 84ee6db commit 8d338cdCopy full SHA for 8d338cd
compare_version_numbers.py
@@ -0,0 +1,25 @@
1
+class Solution:
2
+ """
3
+ @param version1: the first given number
4
+ @param version2: the second given number
5
+ @return: the result of comparing
6
7
+ def compareVersion(self, version1, version2):
8
+ # Write your code here
9
+ v1s = version1.split('.') # 先分隔字符串,如果不用python还是建议直接扫字符串比较。
10
+ v2s = version2.split('.')
11
+ v1s = [int(v) for v in v1s]
12
+ v2s = [int(v) for v in v2s]
13
+ for i in range(min(len(v1s), len(v2s))): # 以短的为基准,如果长度一样,那么长得赢了。
14
+ if v1s[i] < v2s[i]:
15
+ return -1
16
+ elif v1s[i] > v2s[i]:
17
+ return 1
18
+ if len(v1s) == len(v2s):
19
+ return 0
20
+ elif len(v1s) > len(v2s):
21
22
+ else:
23
24
+
25
+# medium: https://www.lintcode.com/problem/compare-version-numbers
0 commit comments