-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path165.cpp
More file actions
38 lines (36 loc) · 838 Bytes
/
165.cpp
File metadata and controls
38 lines (36 loc) · 838 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
33
34
35
36
37
38
//
// 165.cpp
// leetcode
//
// Created by R Z on 2018/7/19.
// Copyright © 2018年 R Z. All rights reserved.
//
#include <stdio.h>
#include <string>
using namespace std;
class Solution {
public:
int compareVersion(string version1, string version2) {
int l1=version1.size();
int l2=version2.size();
int i=0, j=0;
int n1=0, n2=0;
while(i<l1 || j<l2){
while(version1[i]!='.' && i<l1){
n1=n1*10+(version1[i]-'0');
i++;
}
while(version2[j]!='.' && j<l2){
n2=n2*10+(version2[j]-'0');
j++;
}
if(n1>n2) return 1;
else if(n1<n2) return -1;
i++;
j++;
n1=0;
n2=0;
}
return 0;
}
};