# Leetcode 165. Compare Version Numbers

1. Description

## 2. Solution

• Version 1
```class Solution:
def compareVersion(self, version1: str, version2: str) -> int:
v1 = version1.split('.')
v2 = version2.split('.')

length1 = len(v1)
length2 = len(v2)

for i in range(min(length1, length2)):
if int(v1[i]) < int(v2[i]):
return -1
elif int(v1[i]) > int(v2[i]):
return 1
if length1 > length2:
for i in range(length2, length1):
if int(v1[i]) > 0:
return 1
else:
for i in range(length1, length2):
if int(v2[i]) > 0:
return -1
return 0```

## Reference

1. https://leetcode.com/problems/compare-version-numbers/

0 条评论

• ### Leetcode 165 Compare Version Numbers

Compare two version numbers version1 and version2. If version1 > version2 retu...

• ### leetcode 165 Compare Version Numbers

Compare two version numbers version1 and version2. If version1 > version2 ret...

• ### Leetcode: Compare Version Numbers

题目： Compare two version numbers version1 and version2. If version1 > version...

• ### Leetcode Golang 165. Compare Version Numbers.go

版权声明：原创勿转 https://blog.csdn.net/anakinsun/article/details/88992819

• ### 算法细节系列（34）：再见字符串（2）

版权声明：本文为博主原创文章，未经博主允许不得转载。 https://blog.csdn.n...

• ### DP、DFS-LeetCode 198、332、165（DP, DFS）

你是一个专业的小偷，计划偷窃沿街的房屋。每间房内都藏有一定的现金，影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统，如果两间相邻的房屋在同一晚上被小...

• ### numpy.isclose

版权声明：本文为博主原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接和本声明。 ...

• ### numpy.allclose

numpy.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]