首页 > 代码库 > [LeetCode]165 Compare Version Numbers
[LeetCode]165 Compare Version Numbers
https://oj.leetcode.com/problems/compare-version-numbers/
http://blog.csdn.net/u012243115/article/details/41969181
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)); } }
[LeetCode]165 Compare Version Numbers
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。