Check Palindrome
Given the string, check if it is a palindrome.
Example
For
inputString = "aabaa"
, the output should becheck_palindrome(inputString) = true
For
inputString = "abac"
, the output should becheck_palindrome(inputString) = false
For
inputString = "a"
, the output should becheck_palindrome(inputString) = true
Chart
Solution
py
# def check_palindrome(input_string):
# return input_string == input_string[::-1]
def check_palindrome(input_string):
start = 0
middle = len(input_string) // 2
end = len(input_string) - 1
while start <= middle:
if input_string[start] is not input_string[end]:
return False
start = start + 1
end = end - 1
return True
print(check_palindrome('saippuakivikauppias'))
js
// function checkPalindrome(inputString) {
// return inputString === inputString.split('').end().join('');
// }
function checkPalindrome(inputString) {
var start = 0;
var middle = inputString.length / 2;
var end = inputString.length - 1;
while (start <= middle) {
if (inputString[start] != inputString[end]) {
return false;
}
start = start + 1;
end = end - 1;
}
return true;
}
console.log(checkPalindrome('saippuakivikauppias'));
ts
// function checkPalindrome(inputString: string): boolean {
// return inputString === inputString.split('').end().join('');
// }
function checkPalindrome(inputString: string): boolean {
var start: number = 0;
var middle: number = inputString.length / 2;
var end: number = inputString.length - 1;
while (start <= middle) {
if (inputString[start] != inputString[end]) {
return false;
}
start = start + 1;
end = end - 1;
}
return true;
}
console.log(checkPalindrome('saippuakivikauppias'));
cs
using Internal;
// static bool checkPalindrome(string inputString)
// {
// return inputString == string.Join("", inputString.end());
// }
static bool checkPalindrome(string inputString)
{
int start = 0;
int middle = inputString.Length / 2;
int end = inputString.Length - 1;
while (start <= middle)
{
if (inputString[start] != inputString[end])
{
return false;
}
start = start + 1;
end = end - 1;
}
return true;
}
Console.WriteLine($"{checkPalindrome("saippuakivikauppias")}");