Skip to content

Instantly share code, notes, and snippets.

@earobinson
Created September 25, 2015 19:04
Show Gist options
  • Save earobinson/1ffd7663e0601f26e5b5 to your computer and use it in GitHub Desktop.
Save earobinson/1ffd7663e0601f26e5b5 to your computer and use it in GitHub Desktop.
'aba' => true
'abc' => false
public bool check(string sInput)
{
bool ret = true;
char[] forward = new char[sInput.Length];
char[] backward = new char[sInput.Length];
for (int i=0;i<sInput.Length;i++)
forward[i] = sInput.substring(i,1);
for (int i=sInput.Length-1;i>=0;i--)
backward[i] = sInput.Substring(i,1);
int index = sInput.Length-1;
for (int i=0;i<sInput.Length;i++)
{
if (forward[i] != backward[index])
{
ret = false;
break;
}
index -=1;
}
return ret;
}
'abcba'
public bool check(char[] sInput)
{
bool bRet = true;
for (int i=0;i<sInput.Length-i-1;i++)
{
if (sInput[i] != sInput[sInput.Length-i-1])
{
ret = false;
break;
}
}
return ret;
}
''
public bool check (string sInput)
{
if (sInput.length == 1 || sInput.length==0)
return true;
else if (sInput.substring(0,1) == sInput.substring(sInput.length-1,1))
{
if (sInput.length ==2)
return true;
else
return check (sInput.substring(1,sInput.length-1));
}
else
return false;
}
public bool check (string sInput)
{
if (sInput.length == 1 || sInput.length==0)
return true;
else if (sInput.substring(0,1) == sInput.substring(sInput.length-1,1))
{
if (sInput.length ==2)
return true;
else
return check (sInput.substring(1,sInput.length-1));
}
else
return false;
}
'rise to vote sir'
' '
public bool copycheck (string sInput)
{
int i, j;
if (sInput.length == 1 || sInput.length==0)
return true;
else
{
i=0;
j= sInput.length-1 ;
if (sInput.substring(0,1) == ' ')
{
while (sInput.substring(i,1) == ' ' && i<sInput.length-1)
i++;
}
if (sInput.substring (sInput.length-1,1) == ' ')
{
while (sInput.substring(j,1) == ' ' && j>0)
j--;
}
if (sInput.substring(i,1) == sInput.substring(j,1))
{
if (sInput.length ==2)
return true;
else
return check (sInput.substring(1,sInput.length-1));
}
else
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment