```
public class Solution {
public int compareVersion(String version1, String version2) {
String []num1 = version1.split("\\.");
String []num2 = version2.split("\\.");
int i=0,j=0;
for (;i<=num1.length-1&&j<=num2.length-1;i++,j++)
if (Integer.parseInt(num1[i])>Integer.parseInt(num2[j])) return 1;
else if (Integer.parseInt(num1[i])<Integer.parseInt(num2[j])) return -1;
for(;i<=num1.length-1;i++)
if (Integer.parseInt(num1[i])!=0) return 1;
for(;j<=num2.length-1;j++)
if (Integer.parseInt(num2[j])!=0) return -1;
return 0;
}
}
```

After splitting i checked if any of the digits in the head is greater than the other. If not then tries to remove trailing zeroes in versions . If the version number doesn't contain zeroes it returns the version number as highest.