-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_05.cpp
59 lines (54 loc) · 1.4 KB
/
01_05.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
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
class Solution {
public:
bool oneEditAway(string first, string second) {
if(first.compare(second)==0){
return true;
}
if(first.size()<second.size()){
string temp=second;
second=first;
first=temp;
}
if(first.size()-second.size()>=2){
return false;
}
bool legal=true;
if(first.size()==second.size()){
int differences=0;
for(int i=0;i<first.size();i++){
if(first[i]!=second[i]){
differences++;
}
if(differences>=2){
legal=false;
break;
}
}
}else{
int n=second.size();
int j_first=0; int j_second=0;
int num_dif=0;
while(j_second<n){
if(first[j_first]!=second[j_second]){
num_dif++;
j_first++;
}else{
j_first++;
j_second++;
}
if(num_dif>=2){
legal=false;
break;
}
}
}
return legal;
}
};
int main(){
return 0;
}