# Simple Java Solution Using BigInteger

#1
``````import java.math.*;
public class Solution {
public int compareVersion(String A, String B) {
String[] Apart = A.split("\\.");
String[] Bpart = B.split("\\.");

int Asize = Apart.length;
int Bsize = Bpart.length;

if(Asize > Bsize) {
try {
for(int i = 0; i < Bsize; i++) {
if(Long.parseLong(Apart[i]) > Long.parseLong(Bpart[i])) {
return 1;
} else if(Long.parseLong(Apart[i]) < Long.parseLong(Bpart[i])) {
return -1;
} else {
continue;
}
}
if(Integer.parseInt(Apart[Asize - 1]) == 0) return 0;
return 1;
} catch(Exception e) {
for(int i = 0; i < Bsize; i++) {
BigInteger Ax = new BigInteger(Apart[i]);
BigInteger Bx = new BigInteger(Bpart[i]);
if(Ax.compareTo(Bx) == 1) {
return 1;
} else if(Ax.compareTo(Bx) == -1) {
return -1;
} else {
continue;
}
}
if(Integer.parseInt(Apart[Asize - 1]) == 0) return 0;
return 1;
}
}
else if(Asize < Bsize) {
try {
for(int i = 0; i < Asize; i++) {
if(Long.parseLong(Apart[i]) > Long.parseLong(Bpart[i])) {
return 1;
} else if(Long.parseLong(Apart[i]) < Long.parseLong(Bpart[i])) {
return -1;
} else {
continue;
}
}
if(Integer.parseInt(Bpart[Bsize - 1]) == 0) return 0;
return -1;
} catch(Exception e) {
for(int i = 0; i < Asize; i++) {
BigInteger Ax = new BigInteger(Apart[i]);
BigInteger Bx = new BigInteger(Bpart[i]);
if(Ax.compareTo(Bx) == 1) {
return 1;
} else if(Ax.compareTo(Bx) == -1) {
return -1;
} else {
continue;
}
}
if(Integer.parseInt(Bpart[Bsize - 1]) == 0) return 0;
return -1;
}
}
else {
try {
for(int i = 0; i < Asize; i++) {
if(Long.parseLong(Apart[i]) > Long.parseLong(Bpart[i])) {
return 1;
} else if(Long.parseLong(Apart[i]) < Long.parseLong(Bpart[i])) {
return -1;
} else {
continue;
}
}
return 0;
} catch(Exception e) {
for(int i = 0; i < Asize; i++) {
BigInteger Ax = new BigInteger(Apart[i]);
BigInteger Bx = new BigInteger(Bpart[i]);
if(Ax.compareTo(Bx) == 1) {
return 1;
} else if(Ax.compareTo(Bx) == -1) {
return -1;
} else {
continue;
}
}
return 0;
}
}
}
}``````