01. Odd Even Problem
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
string oddEven(string s) {
vector<int> c(26, 0);
for(int i = 0; i < s.size(); ++i)
++c[s[i] - 'a'];
int cnt = 0;
for(int i = 0; i < 26; ++i)
if(c[i] && c[i] % 2 == (i + 1) % 2)
++cnt;
return cnt % 2 ? "ODD" : "EVEN";
}
};Contribution and Support
Last updated