#40 - compare two versions
You are given two version numbers version1 and version2, represented as strings. Your task is to implement a function to compare the two versions.
If
version1is greater thanversion2, return1.If
version1is less thanversion2, return-1.If
version1is equal toversion2, return0.
Each version number may contain multiple components separated by dots (.). Each component contains only digits and may not contain leading zeros, except for the zero itself.
Example 1
version1 = "1.0.1"
version2 = "1"
1Example 2
version1 = "7.5.2.4"
version2 = "7.5.3"
-1Example 3
version1 = "1.1.1"
version2 = "1.1.1"
0
Last updated