import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 比较版本号
* @param version1 string字符串
* @param version2 string字符串
* @return int整型
*/
public int compare (String version1, String version2) {
int index1 = 0,index2 = 0;
String[] arr1 = splitByDigit(version1);
String[] arr2 = splitByDigit(version2);
while(index1 < arr1.length && index2 < arr2.length){
if(parseInt(arr1[index1].toCharArray()) < parseInt(arr2[index2].toCharArray())){
return -1;
}else if(parseInt(arr1[index1].toCharArray()) > parseInt(arr2[index2].toCharArray())){
return 1;
}else {
index1++;
index2++;
}
}
while(index1 < arr1.length){
if(parseInt(arr1[index1].toCharArray()) != 0){
return 1;
}
index1 ++;
}
while(index2 < arr2.length){
if(parseInt(arr2[index2].toCharArray()) != 0){
return 1;
}
index2 ++;
}
return 0;
}
private String[] splitByDigit(String s){
int begin = -1,rush = 0;
char[] arr = s.toCharArray();
List<String> list = new ArrayList<>();
while(rush < arr.length){
begin = rush;
while(rush < arr.length && arr[rush] != '.') {
rush++;
}
list.add(new String(arr,begin,rush - begin));
++rush;
}
return list.toArray(new String[0]);
}
private int parseInt(char[] arr){
int i = 0;
// 跳过前导 0
while(arr[i] == 0) {
i++;
}
int ret = 0;
while(i < arr.length){
ret += ret * 10 + (arr[i++] - '0');
}
return ret;
}
}