leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0165.cpp (730B)


0 class Solution {
1 public:
2 int compareVersion(string version1, string version2) {
3 stringstream s1(version1), s2(version2);
4 vector<int> v1, v2;
6 string crnt;
7 while (getline(s1, crnt, '.'))
8 v1.push_back(stoi(crnt));
9 while (getline(s2, crnt, '.'))
10 v2.push_back(stoi(crnt));
12 while (v1.size() < v2.size())
13 v1.push_back(0);
14 while (v1.size() > v2.size())
15 v2.push_back(0);
17 int i = 0, j = 0;
18 while (i < v1.size() && j < v2.size()) {
19 if (v1[i] > v2[j]) return 1;
20 if (v1[i] < v2[j])
21 return -1;
22 else
23 i++, j++;
24 }
26 return 0;
27 }
28 };