bool Check(string str, int s, int e)
{
while (s <= e)
{
if (str[s++] != str[e--])
return false;
}
return true;
}
bool validPalindrome(string str)
{
int s = 0, e = str.length() - 1;
while (s <= e)
{
if (str[s] != str[e])
return Check(str, s + 1, e) || Check(str, s, e - 1);
s++;
e--;
}
return true;
}
'코딩테스트 > LeetCode' 카테고리의 다른 글
[LeetCode] Remove All Adjacent Duplicates in String II (0) | 2023.12.12 |
---|---|
[LeetCode] Remove All Adjacent Duplicates In String (0) | 2023.12.12 |
[LeetCode] Excel Sheet Column Number (0) | 2023.12.11 |
[LeetCode] Evaluate Reverse Polish Notation (0) | 2023.12.11 |
[LeetCode] Rotate Array (0) | 2023.12.08 |