Created
February 1, 2016 23:32
-
-
Save kfarst/49cd3f61753250f27535 to your computer and use it in GitHub Desktop.
Thomas Java Palindrome Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
class Solution { | |
private static boolean isPalindrome( final String input ) { | |
if(input.length()==0){ | |
return false; | |
} | |
String intput2 = input.replace(" ",""); | |
int length = intput2.length()-1; | |
for (int i=0; i<length/2; i++){ | |
char frontChar =intput2.charAt(i); | |
char backChar =intput2.charAt(length-i); | |
if(frontChar!=backChar){ | |
return false; | |
} | |
} | |
return true; | |
} | |
public static void main(String[] args) { | |
/* | |
* 1) Write a function that returns true if a string is a palindrome | |
* - Palindrome: a word, phrase, or sequence that reads the same backward | |
* as forward, e.g., madam or nurses run. | |
*/ | |
System.out.println("so nnos -> " + isPalindrome("sonnos")); | |
System.out.println("kayak -> " + isPalindrome("kay ak")); | |
System.out.println("canucks -> " + isPalindrome("c anucks")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment