FunctionRacerProblemsRace

Compare Version Numbers

EasyStringsPython, JavaScript, TypeScript, Java, C++

A version is whole numbers joined by dots, like 1.2.10. Compare two versions part by part from the left, as numbers (so 10 is bigger than 9, and 01 equals 1). A missing part counts as 0.

Return -1 if version1 is smaller, 1 if it is larger, and 0 if they are equal.

Example 1

version1 "1.01"
version2 "1.001"
returns 0

Both parts equal 1 and 1, so 0.

Example 2

version1 "1.0"
version2 "1.0.1"
returns -1

The missing third part is 0, which is less than 1: -1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems