https://oj.leetcode.com/problems/compare-version-numbers/ java
http://blog.csdn.net/u012243115/article/details/41969181 ide
public class Solution { public int compareVersion(String version1, String version2) { if (version1 == null || version2 == null) return 0; // Invalid input. // NOTE!! // Here is the tricky point. String[] v1 = version1.split("\\."); String[] v2 = version2.split("\\."); for (int i = 0 ; i < v1.length || i < v2.length ; i ++) { int value1 = i < v1.length ? Integer.parseInt(v1[i]) : 0; int value2 = i < v2.length ? Integer.parseInt(v2[i]) : 0; int r = Integer.compare(value1, value2); if (r != 0) return r; } return 0; } private int compare(String a, String b) { return Integer.compare(Integer.parseInt(a), Integer.parseInt(b)); } }