Version Order
Software versions are often written with dots, like 1.0.3, and compared part by part from left to right. Given two strings version1 and version2, compare each part as an integer, ignoring leading zeros and treating missing parts as 0. Return -1 if the first version is smaller, 1 if it is larger, and 0 if they are equal.
Примеры
Ввод
"1.01", "1.001"Вывод
0Ввод
"1.0", "1.0.0"Вывод
0Ввод
"0.1", "1.1"Вывод
-1Нужно реализовать
def compare_version(version1, version2):
Теги
stringstwo-pointersarray
Log in om je inzendingsgeschiedenis te zien
InloggenLog in om de AI-mentor te gebruiken
InloggenVisible tests
1
Input
"1.01", "1.001"Expected
02
Input
"1.0", "1.0.0"Expected
03
Input
"0.1", "1.1"Expected
-14
Input
"1.2", "1.10"Expected
-15
Input
"7.5.2.4", "7.5.3"Expected
-16
Input
"1.0.0", "1"Expected
0Focus radio
Paused · SomaFM · Fluid