#include <stdafx.h>
#include <string.h>
#include <stdio.h>
bool CheckRotation(const char *pStr1, cosnt char *pStr2)
{
int iLen1 = strlen(pStr1);
int iLen2 = strlen(pStr2);
if(iLen1 != iLen2)
return false;
char* pStrComb = new char[2 * iLen1];
strcpy(pStrComb, pStr1);
strcat(pStrComb, pStr1);
if(isSubstring(pStrComb, pStr2))
{
delete[] pStrComb;
return true;
}
delete[] pStrComb;
return false;
}
bool isSubstring(const char *pStr1, const char *pStr2)
{
if(strlen(pStr1) < strlen(pStr2))
return false;
for(int i = 0; i <= strlen(pStr1) - strlen(pStr2); i++)
{
for(int j = 0; j < strlen(pStr2); j++)
{
if(pStr1[i + j] != pStr1[j])
break;
}
if(j == strlen(pStr2))
return true;
}
return false;
}
cracking the coding interview problem solution 1.8
原创
©著作权归作者所有:来自51CTO博客作者nicolin7的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Python Coding Interview
Python Coding InterviewPython AdvancedJupyterJupyter Notebook
Jupyter Notebook Jupyter Coding Interview Advanced Python
















