commit dd8db0d2592ad603c959758eee9fe52d3f655f1b
parent e2e132c5429dbcaf48d671ec44ac0cc52c051f05
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Wed, 25 Jan 2023 12:09:13 +0100
LeetCode 75 I: Day 5
Diffstat:
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/Problems/0409.cpp b/Problems/0409.cpp
@@ -0,0 +1,15 @@
+class Solution {
+public:
+ int longestPalindrome(string s) {
+ unordered_map<char, int> um;
+ for (char c : s) um[c]++;
+
+ int res = 0;
+ bool odd = false;
+ for (auto [c, v] : um) {
+ if (v % 2 && !odd) odd = true;
+ res += v / 2;
+ }
+ return res * 2 + odd;
+ }
+};
diff --git a/README.md b/README.md
@@ -155,6 +155,7 @@ for solving problems.
| 0399 | Medium | [Evaluate Division](Problems/0399.cpp) |
| 0402 | Medium | [Remove K Digits](Problems/0402.cpp) |
| 0404 | Easy | [Sum of Left Leaves](Problems/0404.cpp) |
+| 0409 | Easy | [Longest Palindrome](Problems/0409.cpp) |
| 0412 | Easy | [Fizz Buzz](Problems/0412.cpp) |
| 0414 | Easy | [Third Maximum Number](Problems/0414.cpp) |
| 0415 | Easy | [Add Strings](Problems/0415.cpp) |