Skip to content

Suggestion to the code #3170

@Sharanyaaa08

Description

@Sharanyaaa08

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions