mramachandran / games

0 stars 0 forks source link

create palindrome function in Java #2

Open mramachandran opened 3 months ago

mramachandran commented 3 months ago

Certainly! Here is a detailed function description for a developer to create a palindrome checker function in Java:

Function Description: isPalindrome

Objective:

The objective of this function is to determine if a given string is a palindrome. A palindrome is a string that reads the same backward as forward.

Function Signature:

public static boolean isPalindrome(String str)

Parameters:

Return Value:

Steps to Implement:

  1. Normalize the Input:

    • Convert the string to lower case to make the check case-insensitive.
    • Remove all non-alphanumeric characters from the string.
  2. Initialize Pointers:

    • Use two pointers: one starting at the beginning of the string (left) and the other at the end of the string (right).
  3. Check Characters from Both Ends:

    • Iterate over the string using the two pointers.
    • Compare characters at the left and right pointers.
    • If the characters are the same, move the pointers towards the center.
    • If the characters are different, return false.
  4. Return Result:

    • If all characters match, return true.

Edge Cases:

mramachandran commented 3 months ago
GamerMRB commented 3 months ago

finished

GamerMRB commented 3 months ago

The code is efficient to the point where it determined that "Edna Waterfall" by Howard W. Bergerson was a palindrome. This poem, 1,039 words, is the longest palindrome poem in the world!