| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include <iostream>
- #include <cstdint>
- #include <vector>
- #include <string>
- using std::vector;
- using std::string;
- class Solution {
- public:
- string firstPalindrome(vector<string>& words) {
- auto len = words.size();
- auto i = len;
- for ( i = 0; i < len; ++i ) {
- string s = words[i];
- unsigned int slen = (unsigned int)s.length() - 1;
- unsigned int end = ((unsigned int) (slen / 2)) + 1;
- for ( unsigned int j = 0; j < end; ++j ) {
- if ( s[j] != s[slen-j] ) { goto outer; }
- }
- return s;
- outer: ;
- }
- return "";
- }
- };
- void r(vector<string>& w) {
- std::cout << "Solution().firstPalindrome([";
- for ( uint64_t i = 0; i < w.size(); ++i ) {
- if ( i == 0 ) { std::cout << "\"" << w[i] << "\""; continue; }
- std::cout << ", \"" << w[i] << "\"";
- }
- std::cout << "]) = \"" << Solution().firstPalindrome(w) << "\"";
- };
- int main(void) {
- vector<string> w1 = {"abc", "car", "ada", "racecar", "cool"};
- r(w1);
- return 0;
- }
|