2
public int compareVersion(String version1, String version2) {3
// Here we are going to Split the numbers by . but since we cannot do that in java we will4
// replace . with # and then do it5
version1 = version1.replace('.', '#');6
version2 = version2.replace('.', '#');8
String v1[] = version1.split("#");9
String v2[] = version2.split("#");13
while (i < v1.length || i < v2.length) {14
// we will have inital value 0 as our array can out out index so taking that in18
// Here we are using removeing Zero function which will remove all the zeros before the string20
i1 = Integer.valueOf(removezero(v1[i]));23
i2 = Integer.valueOf(removezero(v2[i]));25
// and the rest is just the comparison33
// if all the statments are false then at last we can say that they are equal37
String removezero(String s) {40
while (i < s.length()) {41
if (s.charAt(i) != '0') {42
result = s.substring(i, s.length());47
return result != "" ? result : "0";