Efficiently reverse the order of the words (not characters) in an array of characters

前端 未结 21 1936
[愿得一人]
[愿得一人] 2020-11-28 04:40

Given an array of characters which forms a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.

Example input and

21条回答
  •  清歌不尽
    2020-11-28 04:58

    Efficient in terms of my time: took under 2 minutes to write in REBOL:

    reverse_words: func [s [string!]] [form reverse parse s none]
    

    Try it out: reverse_words "this is a string" "string a is this"

提交回复
热议问题