标签:
题目描述:public class Solution { public int CompareVersion(string version1, string version2) { var v1 = version1; var v2 = version2; var v1Arr = v1.Split(‘.‘); var v2Arr = v2.Split(‘.‘); var i = 0; var j = 0; while(i < v1Arr.Length || j < v2Arr.Length){ if(i == v1Arr.Length){ return int.Parse(v2Arr[i]) == 0 ? 0 : -1; } if(i == v2Arr.Length){ return int.Parse(v1Arr[i]) == 0 ? 0 : 1; } if(int.Parse(v1Arr[i]) == int.Parse(v2Arr[j])){ i++; j++; continue; } return int.Parse(v1Arr[i]) > int.Parse(v2Arr[j]) ? 1 : -1; } return 0; } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
LeetCode -- Compare Version Numbers
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/48379733