4 ms·
There're more string copies that can be optimized away for the C++ solution: 1. When filling the map with `word`, can use emplace with std::move of the `word`
by techolic 6y ago
There're more string copies that can be optimized away for the C++ solution:
1. When filling the map with `word`, can use emplace with std::move of the `word` instead of operator[] because `word` is no longer needed after that, after checking that it's not already in the map
2. Constructing the vector (for sorting) with all pairs from the map ends up copying the whole map's worth of data! Can use iterator of the map instead of the key of the map in the pair. This may also make sort() faster because it may be cheaper to move an iterator than a string during sort()