力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台
代码如下:
class Solution {public int compareVersion(String version1, String version2) {int i = 0, j = 0;while(i < version1.length() || j < version2.length()){long num1 = 0;while(i < version1.length() && version1.charAt(i) != '.'){num1 = num1*10 + (version1.charAt(i) - '0');i++;}i++;long num2 = 0;while(j < version2.length() && version2.charAt(j) != '.'){num2 = num2*10 + (version2.charAt(j) - '0');j++;}j++;if(num1 > num2){return 1;}if(num1 < num2) {return -1;}}return 0;}
}