165. Compare Version Numbers
Python
https://leetcode.com/problems/compare-version-numbers/
from itertools import zip_longest
class Solution:
def compareVersion(self, version1: str, version2: str) -> int:
for pair in zip_longest(version1.split('.'), version2.split('.')):
raw1, raw2 = pair
v1 = 0 if raw1 is None else int(raw1)
v2 = 0 if raw2 is None else int(raw2)
if v1 < v2:
return -1
if v1 > v2:
return 1
return 0