-
Notifications
You must be signed in to change notification settings - Fork 0
/
165.java
28 lines (28 loc) · 879 Bytes
/
165.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
class Solution {
public int compareVersion(String version1, String version2) {
String[] v1 = version1.split("\\.");
String[] v2 = version2.split("\\.");
int min = Math.min(v1.length,v2.length);
for(int i=0;i<min;i++){
int a = Integer.parseInt(v1[i]);
int b = Integer.parseInt(v2[i]);
if(a<b) return -1;
if(a>b) return 1;
}
if(v1.length>v2.length){
for(int i=v2.length;i<v1.length;i++){
int temp = Integer.parseInt(v1[i]);
if(temp!=0) return 1;
}
return 0;
}
if(v1.length<v2.length){
for(int i=v1.length;i<v2.length;i++){
int temp = Integer.parseInt(v2[i]);
if(temp!=0) return -1;
}
return 0;
}
return 0;
}
}