Pergunta de entrevista da empresa Meta

Write a palindrome-checking function

Respostas da entrevista

Sigiloso

19 de nov. de 2012

This has a N/2 complexity : function isPalyndrome($str) { $array = str_split($str); $size = count($array); $pivot = floor($size / 2); for($i = 0; $i < $pivot; $i++) { if($array[$i] != $array[$size - $i - 1]) { return false; } } return true; }

2

Sigiloso

29 de dez. de 2012

#include #include using namespace std; bool IsPalindrome(const string& input) { for (int i = 0; i < input.size()/2; ++i) { if (input[i] != input[input.size()-i-1]) { return false; } } return true; } int main() { const string str("madam"); const string str1("madama"); cout << IsPalindrome(str) << endl; cout << IsPalindrome(str1) << endl; return 0; }

Sigiloso

15 de nov. de 2012

My solution walked char pointers back from the end and forward from the beginning of the string, returning true if the crossed over and false if the two chars pointed to didn't match.