I forget about java, but the algorithm seems not hard.

來源: 2009-03-03 23:14:21 [博客] [舊帖] [給我悄悄話] 本文已被閱讀:

I suppose the word separator is a space. One algorithm is like this:

(1) Reverse the string char by char. This is easy.
(2) Reverse each word. You need to find the start and end positions of each word.

This algorithm scans the string twice, and should be fast enough.

It is possible to scan the string only once, but the algorithm sounds more complicated to me.