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