Check whether the string is symmetric, how to test your result
Interview Answers
Anonymous
Jan 18, 2011
actually yo do not need to break from the algorithm, just return false when you find they are different, then return true after the iteration.
2
Anonymous
Mar 31, 2011
boolean isSymetric(String str) {
for (int i=0; i
1
Anonymous
Jan 15, 2011
#include
#include
using namespace std;
bool isSymmetric(string str)
{
int len = str.length();
for(int i=0;i> str;
cout << isSymmetric(str);
return 0;
}
Anonymous
Jan 15, 2011
i is in scope of for, so u need to define i earlier to access it later!
Anonymous
Jan 27, 2011
The code is close to correct but will never return true
Anonymous
Mar 31, 2011
#include
#include
using namespace std;
bool isSymmetric(string str)
{
int len = str.length();
int i = 0;
int j = len -1;
do
{
if (str[i] == str[j])
{
i++;
j--;
}
else
{
return false;
}
}
while(i> str;
cout <