#40 - compare two versions
You are given two version numbers version1
and version2
, represented as strings. Your task is to implement a function to compare the two versions.
If
version1
is greater thanversion2
, return1
.If
version1
is less thanversion2
, return-1
.If
version1
is equal toversion2
, return0
.
Each version number may contain multiple components separated by dots (.
). Each component contains only digits and may not contain leading zeros, except for the zero itself.
Example 1
Example 2
Example 3
Last updated