import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 比较版本号
* @param version1 string字符串
* @param version2 string字符串
* @return int整型
*/
public int compare (String version1, String version2) {
// write code here
// split中传入的字符串会被当做正则表达式,而 . 表示匹配任意单个字符(除了换行符)
// 明显不能只使用.,应该使用转义字符修饰.
String[] a1 = version1.split("\\.");
String[] a2 = version2.split("\\.");
//System.out.println(a1.length);
int i = 0, j = 0;
while(i < a1.length && j < a2.length){
int m = Integer.parseInt(a1[i]);
int n = Integer.parseInt(a2[j]);
//System.out.println(m + " " + n);
if(m < n){
return -1;
}else if(m > n){
return 1;
}
i++;
j++;
}
while(i < a1.length && a1[i].equals("0")){
i++;
}
if(i < a1.length)return 1;
while(j < a2.length && a2[j].equals("0")){
j++;
}
if(j < a2.length)return -1;
return 0;
}
}