7 ms·
The question is not hard if you are allowed to use extra memory: just tokenize into words, put them into array and reverse, then join them back into a new strin
by bearmf 14y ago
The question is not hard if you are allowed to use extra memory: just tokenize into words, put them into array and reverse, then join them back into a new string.
It is harder to do it in place. I actually did not believe it was possible until looking up the answer on StackExchange. That solution involves a "trick" which one might not figure out under pressure.
- kragen 14y agoI think you can do it in place with four pointers. The "trick" is somewhat generally applicable.