Given two version strings, version1 and version2, compare them. A version string is composed of revisions separated by dots ('.'). Each revision’s value is determined by converting it to an integer, disregarding any leading zeros.
Compare the two version strings by evaluating their revision values from left to right. If one version string contains fewer revisions than the other, treat each missing revision as 0.
Return the result of the comparison as follows:
Return version1 is less than version2.
Return version1 is greater than version2.
Return
Note: Each revision value in
version1andversion2is guaranteed to fit within a32 -bit integer.
Constraints:
version1.length, version2.length
version1 and version2 contain only digits and '.'
version1 and version2 are valid version numbers
All given revisions in version1 and version2 can be stored in a
The key intuition behind this solution is to split both version strings by the dot delimiter into lists of revision strings, then use two pointers to traverse both lists simultaneously, comparing corresponding revision values as integers. If one version has fewer revisions than the other, we ...
Given two version strings, version1 and version2, compare them. A version string is composed of revisions separated by dots ('.'). Each revision’s value is determined by converting it to an integer, disregarding any leading zeros.
Compare the two version strings by evaluating their revision values from left to right. If one version string contains fewer revisions than the other, treat each missing revision as 0.
Return the result of the comparison as follows:
Return version1 is less than version2.
Return version1 is greater than version2.
Return
Note: Each revision value in
version1andversion2is guaranteed to fit within a32 -bit integer.
Constraints:
version1.length, version2.length
version1 and version2 contain only digits and '.'
version1 and version2 are valid version numbers
All given revisions in version1 and version2 can be stored in a
The key intuition behind this solution is to split both version strings by the dot delimiter into lists of revision strings, then use two pointers to traverse both lists simultaneously, comparing corresponding revision values as integers. If one version has fewer revisions than the other, we ...