Created
November 10, 2017 08:01
-
-
Save atonamy/ae9f8d3735035fc9903868e0f1695042 to your computer and use it in GitHub Desktop.
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
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