-
Notifications
You must be signed in to change notification settings - Fork 34
/
Solution.java
32 lines (32 loc) · 954 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Solution {
public int compareVersion(String version1, String version2) {
String[] v1=version1.split("\\.");
String[] v2=version2.split("\\.");
int l1=v1.length;
int l2=v2.length;
for (int i = 0; i < Math.min(l1, l2); i++) {
if (Integer.valueOf(v1[i])<Integer.valueOf(v2[i])) {
return -1;
}else if (Integer.valueOf(v1[i])>Integer.valueOf(v2[i])) {
return 1;
}
}
if (l1==l2) {
return 0;
}else if (l1>l2) {
for (int i = l2; i <l1; i++) {
if (Integer.parseInt(v1[i])!=0) {
return 1;
}
}
return 0;
}else {
for (int i = l1; i < l2; i++) {
if (Integer.parseInt(v2[i])!=0) {
return -1;
}
}
return 0;
}
}
}