Detailed description
The code works correctly
I'd like to suggest an optimization:
bool isPalindrome(const std::string& str) {
int left = 0, right = str.length() - 1;
while (left < right) {
if (str[left] != str[right]) return false;
left++;
right--;
}
return true;
}
Context
space complexity improves from O(n) to O(1).
Here two pointer approach is more space Efficient.
Thank you.
Possible implementation
No response
Additional information
No response
Detailed description
The code works correctly
I'd like to suggest an optimization:
bool isPalindrome(const std::string& str) {
int left = 0, right = str.length() - 1;
while (left < right) {
if (str[left] != str[right]) return false;
left++;
right--;
}
return true;
}
Context
space complexity improves from O(n) to O(1).
Here two pointer approach is more space Efficient.
Thank you.
Possible implementation
No response
Additional information
No response