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.
I forget about java, but the algorithm seems not hard.
所有跟帖:
• 嗯,就是你說的算法 -svm- ♂ (39 bytes) () 03/03/2009 postreply 23:19:12
• you may think it's silly, it's fast -interested1- ♀ (141 bytes) () 03/04/2009 postreply 21:56:38
• 回複:I forget about java, but the algorithm seems not hard. -sub101- ♂ (48 bytes) () 03/04/2009 postreply 06:25:19