Skip to content

Commit 3b6b81f

Browse files
committed
Day-10- BST predeccesor and successor algo + stack implementation
1 parent cb492dd commit 3b6b81f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Cracking the coding interview edition 6
3+
* Problem 1.5
4+
* Three possible types of edit possible on a string
5+
* Insert a char, delete a char or replace a char
6+
* Write a function to check if two given string are one ( or zero ) edit(s) away
7+
*/
8+
9+
10+
bool oneEditReplace( const std::string & src, const std::string & dst )
11+
{
12+
int mismatch = 0;
13+
for ( size_t i = 0; i < src.length(); ++i )
14+
{
15+
if ( src[i] != dst[i] )
16+
{
17+
++mismatch;
18+
}
19+
}
20+
return (mismatch <= 1);
21+
}
22+
23+
bool oneEditInsert( const std::string & src, const std::string & dst )
24+
{
25+
26+
27+
}
28+
29+
30+
31+
bool oneEditAway( const std::string & src, const std::string & dst )
32+
{
33+
int srcLen = src.length();
34+
int dstLen = dst.length();
35+
if ( srcLen == dstLen )
36+
{
37+
return oneEditReplace(src, dst);
38+
}
39+
else if ( srcLen + 1 == dstLen )
40+
{
41+
return oneEditInsert(src, dst);
42+
}
43+
else if ( srcLen - 1 == dstLen )
44+
{
45+
return oneEditRemove(src, dst);
46+
}
47+
return false;
48+
}

0 commit comments

Comments
 (0)