705. Compare Version Numbers

0

Medium

Given two version numbers, version1 and version2, compare them. Version numbers are composed of one or more revisions joined by a dot '.'. Each revision is made up of digits and may contain leading zeros. Every revision contains at least one character. Revisions are indexed from left to right, starting from 0. For example, 2.5.33 and 0.1 are valid version numbers. To compare version numbers, compare their revisions in left-to-right order. Revisions are compared based on their integer value, ignoring any leading zeros. This means that revisions 1 and 001 are considered equal. If a version number does not specify a revision at an index, treat the revision as 0. For instance, version 1.0 is less than version 1.1 because their revision 0s are the same, but their revision 1s are 0 and 1 respectively, and 0 is less than 1. Return the following: If version1 is less than version2, return -1. If version1 is greater than version2, return 1. Otherwise, return 0.

Input Format

Two strings representing version1 and version2

Output Format

-1, 0, or 1

Example

Input

"1.01" "1.001"

Output

0

Constraints

1 <= version1.length, version2.length <= 500 version1 and version2 only consist of digits and '.'. version1 and version2 are valid version numbers. All the given revisions in version1 and version2 can be stored in a 32-bit integer.
Loading...

View Submissions

Console