Determining if a string can be permuted to a palindrome
I much prefer your solution. It's easy to read and straightforward. The difference in size between the 2 is probably not that much. Their code has an unordered_set with a few elements in it. Your code has an unordered_map with likely 26 elements in it. We're talking about 26 * 5 = 130 bytes vs. say 5 or 10 bytes for the set on average. On modern systems, this is not a difference in memory usage. It's all below 1KB. If you're working with some old or oddball hardware and that becomes an issue, you can deal with it then.

However, if I were to see this code in production, I would probably want the following changes:


I would opt for using auto instead of the long type name in this line:




for(std::pair&lt;char, int&gt; letter : letter_count) {


I'd make it:

for(const auto&amp; letter : letter_count) {


As mentioned in the discussion in the comments, making it a reference saves a copy of the pair and making it const lets a reader know that you aren't going to be modifying it.


I'd use more space between operators in the next line:




if(letter.second%2 != 0) {


would become:

if (letter.second % 2 != 0) {


It's just easier to read.


I might make that conditional into a named function just to make it clearer:




bool isOdd(const int x)
{
    return (x % 2) != 0
}

// ...
if  (isOdd(letter.second)) {