Palindrome solving is one of the very beginner question often asked and given by teachers to solve. This can be complicated if you're restricted to use some specific data structure, or using a specific method but it is very simple if you have to solve it with no conditions.
What is palindrome?
Palindrome is a word, string or phrase that reads same forward as well as backwards for example eye, madam, civic, level, refer, 22/2/22, 11:11 are all palindromes.
How to check palindrome? (Video Tutorial)
To check if a word or phrase is palindrome you need to compare original with its reversed version.
Simplest way to do this is given below: or see at github
void main() {
checkPalindrome("eye")? print("Palindrome") : print("Not Palindrome");
checkPalindrome("Eye")? print("Palindrome") : print("Not Palindrome");
checkPalindrome("Bye")? print("Palindrome") : print("Not Palindrome");
checkPalindrome("")? print("Palindrome") : print("Not Palindrome");
}
bool checkPalindrome(String inputString){
return inputString == inputString.split("").reversed.join();
}
0 Comments