运行时间超过 90 的 C++ 代码
之所以退出循环的条件是 i<j 是因为过程中不会出现 i==j 的情况,这是问题是在反转字符串那里写代码发现的
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param str string字符串 待判断的字符串 * @return bool布尔型 */ bool judge(string str) { // write code here int i = 0; int j = str.length() - 1; while( i<j) if(str[i++]!=str[j--]) return false; return true; } };