-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode-165.1.cpp
More file actions
32 lines (29 loc) · 928 Bytes
/
LeetCode-165.1.cpp
File metadata and controls
32 lines (29 loc) · 928 Bytes
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
/*************************************************************************
> File Name: LeetCode-165.1.cpp
> Author: ltw
> Mail: 3245849061@qq.com
> Created Time: Thu 21 May 2020 06:22:23 PM CST
************************************************************************/
#include <iostream>
using namespace std;
class Solution {
public:
int getNext(string &str, int i, int &val) {
val = 0;
while (str[i] && str[i] <= '9' && str[i] >= '0') {
val = val * 10 + str[i] - '0';
i++;
}
if (str[i]) ++i;
return i;
}
int compareVersion(string version1, string version2) {
int i = 0, j = 0, val1, val2;
while (version1[i] || version2[j]) {
i = getNext(version1, i, val1);
j = getNext(version2, j, val2);
if (val1 - val2) return val1 > val2 ? 1 : -1;
}
return 0;
}
};