Skip to content

Commit 67b2d68

Browse files
✨ Day 14; Week 2 ✔️
1 parent b481818 commit 67b2d68

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@
1313
6. [Find All Duplicates in an Array](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/549/week-1-august-1st-august-7th/3414/) ➡️ [CPP Solution](Week1/findDuplicates.cpp)
1414
7. [Vertical Order Traversal of a Binary Tree](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/549/week-1-august-1st-august-7th/3415/) ➡️ [CPP Solution](Week1/verticalTraversal.cpp)
1515

16-
## Week 2 🚧
16+
## Week 2
1717
1. [Path Sum III](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3417/) ➡️ [CPP Solution](Week2/pathSum.cpp)
1818
2. [Rotting Oranges](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3418/) ➡️ [CPP Solution](Week2/orangesRotting.cpp)
1919
3. [Excel Sheet Column Number](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3419/) ➡️ [CPP Solution](Week2/titleToNumber.cpp)
2020
4. [H Index](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3420/) ➡️ [CPP Solution](Week2/hIndex.cpp)
2121
5. [Pascal's Triangle II](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3421/) ➡️ [CPP Solution](Week2/pascalTriangle2.cpp)
2222
6. [Iterator for Combination](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3422/) ➡️ [CPP Solution](Week2/combinationIterator.cpp)
23+
7. [Longest Palindrome](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3423/) ➡️ [CPP Solution](Week2/longestPalindrome.cpp)
24+
25+
## Week 3 🚧
26+
Coming Soon...
27+
28+
## Week 4 🚧
29+
Coming Soon...
30+
31+
## Week 5 🚧
32+
Coming Soon...
2333

2434
## Where to find me? 🌟
2535
* [Website](https://akashwho.codes/)

Week2/longestPalindrome.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int longestPalindrome(string s) {
4+
unordered_map<char, int> m;
5+
bool saw_single_char = false;
6+
int total = 0;
7+
8+
for(char ch: s) m[ch]++;
9+
10+
for(auto &x: m) {
11+
if(x.second % 2 == 0) total += x.second;
12+
else {
13+
total += x.second - 1;
14+
saw_single_char = true;
15+
}
16+
}
17+
18+
return saw_single_char ? total + 1 : total;
19+
}
20+
};

0 commit comments

Comments
 (0)