-
Notifications
You must be signed in to change notification settings - Fork 9
/
9thSep.cpp
47 lines (47 loc) · 1.23 KB
/
9thSep.cpp
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
37
38
39
40
41
42
43
44
45
46
47
class Solution {
public:
int compareVersion(string version1, string version2) {
string temp="";
vector<int> ver1,ver2;
for(int i=0;i<version1.size();i++)
{
if(i==version1.size()-1)
temp+=version1[i];
if(version1[i]=='.' || i==version1.size()-1)
{
ver1.push_back(atoi( temp.c_str() ));
temp="";
}
else
{
temp+=version1[i];
}
}
for(int i=0;i<version2.size();i++)
{
if(i==version2.size()-1)
temp+=version2[i];
if(version2[i]=='.' || i==version2.size()-1)
{
ver2.push_back(atoi( temp.c_str() ));
temp="";
}
else
{
temp+=version2[i];
}
}
if(ver1.size()>ver2.size())
ver2.resize(ver1.size());
else if(ver1.size()<ver2.size())
ver1.resize(ver2.size());
for(int i=0;i<ver1.size();i++)
{
if(ver1[i]>ver2[i])
return 1;
else if(ver1[i]<ver2[i])
return -1;
}
return 0;
}
};