Skip to content

Commit f7ac198

Browse files
committed
Time: 1 ms (76.03%), Space: 41.6 MB (48.13%) - LeetHub
1 parent d661ac6 commit f7ac198

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int compareVersion(String version1, String version2) {
3+
String[] v1 = version1.split("\\.");
4+
String[] v2 = version2.split("\\.");
5+
6+
int n = Math.max(v1.length, v2.length);
7+
for (int i = 0; i < n; i++) {
8+
int num1 = i < v1.length ? Integer.parseInt(v1[i]) : 0;
9+
int num2 = i < v2.length ? Integer.parseInt(v2[i]) : 0;
10+
11+
if (num1 != num2) {
12+
return num1 > num2 ? 1 : -1;
13+
}
14+
}
15+
return 0;
16+
}
17+
}

0 commit comments

Comments
 (0)