Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
35 lines (27 loc) · 951 Bytes

File metadata and controls

35 lines (27 loc) · 951 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
33
34
35
package Algorithms.string;
public class CompareVersion {
public static void main(String[] args) {
compareVersion("1", "0");
}
public static int compareVersion(String version1, String version2) {
if (version1 == null || version2 == null || version1.length() == 0
|| version2.length() == 0) {
return 0;
}
String[] strs1 = version1.split("\\.");
String[] strs2 = version2.split("\\.");
int size1 = strs1.length;
int size2 = strs2.length;
int minSize = Math.min(size1, size2);
for (int i = 0; i < minSize; i++) {
int v1 = Integer.parseInt(strs1[i]);
int v2 = Integer.parseInt(strs2[i]);
if (v1 > v2) {
return 1;
} else if (v1 < v2) {
return -1;
}
}
return 0;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.