class Solution { public: int longestPalindrome(string s) { int n = s.length(); int ans = 0; bool isodd = false; vector mpp(256, 0); for (int i = 0; i < n; i++) { mpp[s[i]]++; } for (int i = 0; i < mpp.size(); i++) { if (mpp[i] % 2 == 0) { ans += mpp[i]; } else { ans += mpp[i] - 1; isodd = true; } } if (isodd) { ans += 1; } return ans; } };
I don't know why I chose a lengthy approach of generating subsequences and checking the longest palindrome :) This is way better and much simpler to implement
i did a similar approach and i got the result as 17 ms, is this just a leet code thing? one suggestion, start doing live coding instead, it'll be more helpful imo
class Solution {
public:
int longestPalindrome(string s) {
int n = s.length();
int ans = 0;
bool isodd = false;
vector mpp(256, 0);
for (int i = 0; i < n; i++) {
mpp[s[i]]++;
}
for (int i = 0; i < mpp.size(); i++) {
if (mpp[i] % 2 == 0) {
ans += mpp[i];
} else {
ans += mpp[i] - 1;
isodd = true;
}
}
if (isodd) {
ans += 1;
}
return ans;
}
};
hehe that ki haal chaal in intro every time is kinda cute
I don't know why I chose a lengthy approach of generating subsequences and checking the longest palindrome :)
This is way better and much simpler to implement
ur original code?
Almost done by me. Good explaination
worked for 46 test cases for me
bhai ki x hai
i did a similar approach and i got the result as 17 ms, is this just a leet code thing?
one suggestion, start doing live coding instead, it'll be more helpful imo
yes it is
although mera 100 % aagaya tha pehla attempt me hi
"aacc" ka kya, ye tho palindrome bhi nh hai,aur question mai diya nhi hai ki substrig palindrome hoga hi..
// isme kyu accept nhi ho rha??
class Solution {
public:
int longestPalindrome(string s) {
int n=s.size();
unordered_mapmp;
for(int i=0;i
bhai x ki mkc🤬😡 (3:00)
Thank you