Compare two software version strings component by component and determine which one is larger.
You are given two version strings, version1 and version2. Each version is made of one or more numeric revision parts separated by dots (.).
Compare the versions from left to right, treating missing revision parts as 0.
Return:
-1 if version1 < version21 if version1 > version20 if they are equalA revision part should be compared as an integer value, so leading zeros do not change its meaning.
version1 and version2-1, 1, or 0 depending on the ordering of the two versions0Example 1
Input
version1 = "1.01", version2 = "1.001"
Output
0
Explanation
Both versions represent the parts [1, 1], so they are equal.
Example 2
Input
version1 = "1.0", version2 = "1.0.0"
Output
0
Explanation
Missing parts are treated as 0, so both versions are equal.
Example 3
Input
version1 = "0.1", version2 = "1.1"
Output
-1
Explanation
At the first differing part, 0 < 1.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.