Created
January 4, 2017 21:11
-
-
Save kell18/0e8c62d15597d14d272dac5b3d4197ee to your computer and use it in GitHub Desktop.
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
| object PalindromeChecker { | |
| def isPalindrome(words: Array[String]) { | |
| words.foreach(w => println(isPalindrome1(w))) | |
| } | |
| def isPalindrome(word: String): Boolean = { | |
| var b = 0 | |
| var e = word.length-1 | |
| while (b < e) { | |
| if (word.charAt(b) != word.charAt(e)) return false | |
| b += 1 | |
| e -= 1 | |
| } | |
| return true | |
| } | |
| def isPalindrome1(word: String) = word == word.reverse | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment