We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 06194a2 commit 4492cccCopy full SHA for 4492ccc
solution/0165.Compare Version Numbers/Solution.java
@@ -0,0 +1,15 @@
1
+class Solution {
2
+ public int compareVersion(String version1, String version2) {
3
+ if(version1 == null || version2 == null) return 0;
4
+ char[] v1 = version1.toCharArray();
5
+ char[] v2 = version2.toCharArray();
6
+ for (int i = 0,j = 0;i < v1.length || j < v2.length;i++,j++){
7
+ int ver1 = 0, ver2 = 0;
8
+ for (;i<v1.length && v1[i]!='.';i++) ver1 = ver1 * 10 + v1[i] - '0';
9
+ for (;j<v2.length && v2[j]!='.';j++) ver2 = ver2 * 10 + v2[j] - '0';
10
+ if(ver1 < ver2) return -1;
11
+ else if(ver1 > ver2) return 1;
12
+ }
13
+ return 0;
14
15
+}
0 commit comments