반응형
https://leetcode.com/problems/find-first-palindromic-string-in-the-array
첫번째로 등장하는 palindrome을 찾아줍니다.
class Solution {
public:
string firstPalindrome(vector<string>& words) {
for(string& word : words)
if(isPalindrome(word)) return word;
return "";
}
bool isPalindrome(string& s) {
for(int i=0; i<s.size() / 2; i++)
if(s[i] != s[s.size() - 1 - i]) return false;
return true;
}
};
반응형
'Algorithm' 카테고리의 다른 글
LeetCode 2971. Find Polygon With the Largest Perimeter (0) | 2024.02.17 |
---|---|
LeetCode 2149. Rearrange Array Elements by Sign (0) | 2024.02.14 |
LeetCode 169. Majority Element (0) | 2024.02.13 |
LeetCode 1463. Cherry Pickup II (0) | 2024.02.12 |
LeetCode 368. Largest Divisible Subset (0) | 2024.02.10 |