Skip to content

Instantly share code, notes, and snippets.

@atonamy
Created November 10, 2017 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atonamy/ae9f8d3735035fc9903868e0f1695042 to your computer and use it in GitHub Desktop.
Save atonamy/ae9f8d3735035fc9903868e0f1695042 to your computer and use it in GitHub Desktop.
fun main(args : Array<String>) {
println("A man, a plan, a canal, Panama!".isContainsPalindrome())
}
fun String.isContainsPalindrome(): Boolean {
// handel edge cases
if(length == 0)
return false
if(length == 1)
return (Character.isLetter(this[0]))
var begin = 0
var end = length-1
var result = false
while(begin <= end) {
if(!Character.isLetter(this[begin])) {
begin++
continue
}
if(!Character.isLetter(this[end])){
end--
continue
}
if(this[begin].toLowerCase() != this[end].toLowerCase())
return false
begin++
end--
result = true
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment