Created
July 1, 2016 18:54
-
-
Save danielrobertson/416704ec82e1d8e0b86da35294d85cc8 to your computer and use it in GitHub Desktop.
is palindrome implementations
This file contains hidden or 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
// using StringBuffer | |
boolean isPalindrome(String s) { | |
StringBuffer stringBuffer = new StringBuffer(s); | |
StringBuffer reverse = new StringBuffer(s); | |
reverse.reverse(); | |
return stringBuffer.toString().equals(reverse.toString()); | |
} | |
// in place | |
boolean isPalindrome(String input) { | |
for(int head = 0, tail = input.length() - 1; head <= tail; head++, tail--) { | |
if(input.charAt(head) != (input.charAt(tail)) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment