题解 | #验证回文字符串(二)#
验证回文字符串(二)
https://www.nowcoder.com/practice/130e1a9eb88942239b66e53ec6e53f51
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param str string字符串
* @return bool布尔型
*/
bool palindrome(string str) {
// write code here
int count = 0;
string::iterator begin = str.begin();
string::iterator end = str.end()-1;
while (begin <= end)
{
if (*begin != *end)
count++;
begin++;
end--;
}
if (count > 1) return false;
return true;
}
};
迭代器的判断
