Compare two version numbers version1 and version2.
If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0.

You may assume that the version strings are non-empty and contain only digits and the . character.
The . character does not represent a decimal point and is used to separate number sequences.
For instance, 2.5 is not "two and a half" or "half way to version three", it is the fifth second-level revision of the second first-level revision.

Example 1:


Input: version1 = "0.1", version2 = "1.1"
Output: -1

Example 2:


Input: version1 = "1.0.1", version2 = "1"
Output: 1

Example 3:


Input: version1 = "7.5.2.4", version2 = "7.5.3"
Output: -1

Difficulty: MEDIUM_HARD
Tags: String algorithms

Amortized analysis
Skill types: Amortized analysis

Starter code:
class Solution:
    def compareVersion(self, version1: str, version2: str) -> int:
        

Solutions:
class Solution:

	def compareVersion(self, version1, version2):
		while version1 and version2:
			result1 = version1.split('.', 1)
			if len(result1) == 2:
				(digit1, version1) = (result1[0], result1[1])
			else:
				digit1 = result1[0]
				version1 = ''
			result2 = version2.split('.', 1)
			if len(result2) == 2:
				(digit2, version2) = (result2[0], result2[1])
			else:
				digit2 = result2[0]
				version2 = ''
			if int(digit1) > int(digit2):
				return 1
			elif int(digit1) < int(digit2):
				return -1
		if version1 and sum(map(lambda x: int(x), version1.split('.'))) != 0:
			return 1
		if version2 and sum(map(lambda x: int(x), version2.split('.'))) != 0:
			return -1
		return 0


class Solution:

	def compareVersion(self, version1, version2):
		(v1, v2) = ([int(i) for i in version1.split('.')], [int(i) for i in version2.split('.')])
		if len(v1) > len(v2):
			v2 += [0] * (len(v1) - len(v2))
		if len(v1) < len(v2):
			v1 += [0] * (len(v2) - len(v1))
		for i in range(len(v1)):
			if v1[i] > v2[i]:
				return 1
			if v1[i] < v2[i]:
				return -1
		return 0


class Solution:

	def compareVersion(self, version1, version2):
		l1 = [int(x) for x in version1.split('.')]
		l2 = [int(x) for x in version2.split('.')]
		max_len = max(len(l1), len(l2))
		l1 += [0] * (max_len - len(l1))
		l2 += [0] * (max_len - len(l2))
		for i in range(0, max_len):
			if l1[i] > l2[i]:
				return 1
			elif l1[i] < l2[i]:
				return -1
		return 0


class Solution:

	def compareVersion(self, version1, version2):
		v1 = version1.split('.')
		v2 = version2.split('.')
		for i in range(max(len(v1), len(v2))):
			a = int(v1[i]) if len(v1) > i else 0
			b = int(v2[i]) if len(v2) > i else 0
			if a > b:
				return 1
			elif a < b:
				return -1
		return 0


class Solution:

	def compareVersion(self, version1, version2):
		if version1 == version2:
			return 0
		else:
			version1_nums = version1.split('.')
			version2_nums = version2.split('.')
			(len1, len2) = (len(version1_nums), len(version2_nums))
			end = max(len1, len2)
			version1_nums.extend([0] * (end - len1))
			version2_nums.extend([0] * (end - len2))
			for i in range(end):
				if int(version1_nums[i]) < int(version2_nums[i]):
					return -1
				elif int(version1_nums[i]) > int(version2_nums[i]):
					return 1
			return 0


class Solution:

	def compareVersion(self, version1, version2):
		(a, b) = ([int(i) for i in version1.split('.')], [int(i) for i in version2.split('.')])
		for i in range(max(len(a), len(b))):
			if i == len(a):
				a.append(0)
			if i == len(b):
				b.append(0)
			if a[i] > b[i]:
				return 1
			elif a[i] < b[i]:
				return -1
		return 0


class Solution:

	def compareVersion(self, version1, version2):
		v1 = version1.split('.')
		v2 = version2.split('.')
		len1 = len(v1)
		len2 = len(v2)
		for i in range(min(len1, len2)):
			if int(v1[i]) != int(v2[i]):
				return 1 if int(v1[i]) > int(v2[i]) else -1
		(v, t) = (v1, 1) if len1 > len2 else (v2, -1)
		for j in v[min(len1, len2):]:
			if int(j) > 0:
				return t
		return 0


class Solution:

	def compareVersion(self, version1, version2):
		v1 = [int(n) for n in version1.split('.')]
		v2 = [int(n) for n in version2.split('.')]
		for i in range(max(len(v1), len(v2))):
			x1 = v1[i] if i < len(v1) else 0
			x2 = v2[i] if i < len(v2) else 0
			if x1 > x2:
				return 1
			if x1 < x2:
				return -1
		return 0