Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MichaelaIvanova/652983acf8ab968287f66bbe22c5177b to your computer and use it in GitHub Desktop.
Save MichaelaIvanova/652983acf8ab968287f66bbe22c5177b to your computer and use it in GitHub Desktop.
public static int solution(string S)
{
var index = 0;
if(string.IsNullOrEmpty(S) || S.Length%2 == 0)
{
index = -1;
}
else if(S.Length == 1)
{
index = 0;
}
else
{
var middle = S.Length / 2;
bool isPadigram = true;
for (int i = 0; i <= middle ; i++)
{
if(S[i] != S[S.Length - 1 - i])
{
isPadigram = false;
break;
}
}
if (isPadigram)
{
index = middle;
}
else
{
index = -1;
}
}
return index;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment