Code Puzzle : Is This String A Palindrome

Is This String A Palindrome

A palindrome is a word that is exactly the same whether read forwards or backwards. What you need to do is write a function that returns true if this string provided is a palindrome.

The idea is simple: solve the coding problem as efficiently as you can, in any language or framework that you find suitable.

Note: Even though there really is nothing stopping you from finding a solution to this on the internet, try to keep honest, and come up with your own answer.  It’s all about the participation!

 

One thought on “Code Puzzle : Is This String A Palindrome

  1. public class PalendromePuzzle {

    public static void main(String… args) {
    String string = “abcdcba “;
    System.out.println(“is it palendrome ” + isPalendrome1(string.trim()));
    System.out.println(“is it palendrome ” + isPalendrome2(string.trim()));
    }

    // core implementation
    private static boolean isPalendrome1(String string) {
    string = string.trim();
    int stringLength = string.length();
    for (int index = 0; index < stringLength / 2; index++) {
    if (!(string.charAt(index) == string.charAt(stringLength – index – 1))) {
    return false;
    }
    }
    return true;
    }

    // liveraged string buffer API
    private static boolean isPalendrome2(String string) {
    return new StringBuffer(string).reverse().toString().equalsIgnoreCase(string);
    }

    }

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s