import java.util.ArrayList;
import java.util.List;
/**
*
Compare two version numbers version1 and version2.
If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.
You may assume that the version strings are non-empty and contain only digits and the . character.
The . character does not represent a decimal point and is used to separate number sequences.
For instance, 2.5 is not "two and a half" or "half way to version three", it is the fifth second-level revision of the second first-level revision.
Here is an example of version numbers ordering:
0.1 < 1.1 < 1.2 < 13.37
*
*/
public class CompareVersionNumbers {
// 69 / 69 test cases passed.
// Status: Accepted
// Runtime: 237 ms
// Submitted: 0 minutes ago
static int compareVersion(String version1, String version2) {
List<Integer> v1 = new ArrayList<Integer>();
List<Integer> v2 = new ArrayList<Integer>();
for (String s : version1.split("\\.")) {
int n = 0;
for (Character c : s.toCharArray())
n = n * 10 + c - '0';
v1.add(n);
}
for (String s : version2.split("\\.")) {
int n = 0;
for (Character c : s.toCharArray())
n = n * 10 + c - '0';
v2.add(n);
}
while(v1.size() != v2.size()) {
if(v1.size() < v2.size()) v1.add(0);
else v2.add(0);
}
for (int i = 0; i < Math.min(v1.size(), v2.size()); i++) {
if(v1.get(i) < v2.get(i)) return -1;
else if(v1.get(i) > v2.get(i)) return 1;
}
return 0;
}
public static void main(String[] args) {
System.out.println(compareVersion("1.0", "1.10"));
}
}