144. Compare Version Numbers

MediumString

Given two version strings, version1 and version2, compare them. A version string consists of revisions separated by dots '.'. The value of the revision is its integer conversion ignoring leading zeros. To compare version strings, compare their revision values in left-to-right order. If one version string has fewer revisions, treat the missing revision values as 0. Return -1 if version1 < version2, 1 if version1 > version2, and 0 otherwise.

Examples

Input: 1.2 1.10

Output: -1

Explanation: Second revisions: 2 < 10.

Constraints

  • 1 <= version1.length, version2.length <= 500
  • version1 and version2 only contain digits and '.'.
  • version1 and version2 are valid version numbers.
Loading...

Run checks all cases above. Submit evaluates all test cases.