Created
January 26, 2022 01:29
-
-
Save iamkingalvarado/d93775d5340aac60d54083951b2bcc49 to your computer and use it in GitHub Desktop.
Palindrome
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
| anitalavalatina | |
| anitalavalatina | |
| larutanatural | |
| romaamor | |
| a | |
| n | |
| i | |
| t | |
| a | |
| l | |
| a | |
| v | |
| 1.- Desarrollar un programa que determine si una palabra/oracion es palindroma o no | |
| a) Todos los palindromos se leen igual al derecho y al reves | |
| ana | |
| oso | |
| oro | |
| anitalavalatina - Si | |
| nitalavalatin - Si | |
| italavalati - si | |
| talavalat - Si | |
| alavala - Si | |
| laval - si | |
| ava - si | |
| v | |
| larutanatural - Si | |
| arutanatura - si | |
| rutanatur - si | |
| utanatu - si | |
| tanat - si | |
| ana - si | |
| n | |
| romaamor - si | |
| omaamo - si | |
| maam - si | |
| aa - si | |
| poroosop - Si | |
| orooso - Si | |
| roos - No // Salida | |
| fun palindromo(oracion: String): Boolean { | |
| if (oracion.size() <= 1) { | |
| return true | |
| } | |
| val firstLetter = oracion[0] | |
| val lastLetter = oracion[oracion.size() - 1] | |
| if (firstLetter == lastLetter) { | |
| val substring = oracion.substring(0).substring(oracion.size() - 1) | |
| return palindromo(substring) | |
| } else { | |
| return false | |
| } | |
| } | |
| palindromo("anitalavalatina") // true | |
| palindromo("lol") // true | |
| palindromo("pajaro") // false | |
| palindromo("poroosop") // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment