A version number is written as several revisions joined by dots, like 2.5.33. Each revision is a number that may have extra zeros at the front. Revisions are counted from the left, starting with revision 0.
Compare two versions, version1 and version2, revision by revision from the left:
- Read each revision as a number, so
1 and 001 are equal.
- If a version has no revision at some position, use
0 for it. So 1.0 and 1 are equal.
- The first revision that is different decides the result.
Return:
-1 if version1 is smaller than version2,
1 if version1 is bigger than version2,
0 if they are equal.
Examples
Example 1:
Input: version1 = "2.10", version2 = "2.9"
Output: 1
Explanation: Revision 0 is equal. Revision 1 is 10 against 9, and 10 is bigger.
Example 2:
Input: version1 = "3.0.0", version2 = "3"
Output: 0
Explanation: The missing revisions of "3" count as 0, so both versions are equal.
Example 3:
Input: version1 = "0.9", version2 = "1.0.1"
Output: -1
Explanation: Revision 0 is 0 against 1, so the first version is smaller.