-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompare_Version_Numbers.java
More file actions
36 lines (36 loc) · 1.01 KB
/
Compare_Version_Numbers.java
File metadata and controls
36 lines (36 loc) · 1.01 KB
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
36
import java.util.*;
import java.io.*;
import java.lang.*;
public class Compare_Version_Numbers {
class Solution {
public int compareVersion(String version1, String version2)
{
int i = 0;
int j = 0;
while(i < version1.length() || j < version2.length())
{
int num1 = 0;
int num2 = 0;
while(i < version1.length() && version1.charAt(i) != '.')
{
num1 = num1 * 10 + (version1.charAt(i++) - '0');
}
while(j < version2.length() && version2.charAt(j) != '.')
{
num2 = num2 * 10 + (version2.charAt(j++) - '0');
}
if(num1 < num2)
{
return -1;
}
if(num1 > num2)
{
return 1;
}
i++;
j++;
}
return 0;
}
}
}