diff options
Diffstat (limited to 'other/longest_palindrome_concat.cpp')
-rw-r--r-- | other/longest_palindrome_concat.cpp | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/other/longest_palindrome_concat.cpp b/other/longest_palindrome_concat.cpp deleted file mode 100644 index 3a42e0a..0000000 --- a/other/longest_palindrome_concat.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "leetcode.h" - -class Solution { -public: - int longestPalindrome(vector<string> &words) { - unordered_map<string, int> um; - for (auto w : words) - ++um[w]; - int ans = 0, center = 0, sz = 2; - for (auto [w, cnt] : um) { - auto reversed = string(rbegin(w), rend(w)); - if (w == reversed) { - ans += 2 * (cnt / 2); - center |= cnt % 2; - } else { - auto it = um.find(reversed); - if (it != end(um)) - ans += min(cnt, it->second); - } - } - return sz * ans + (center ? sz : 0); - } -}; - -int main() { - Solution obj; - vector<string> words = {"lc", "cl", "gg"}; - cout << obj.longestPalindrome(words); -} |