leetcode - [1]Reverse Words in a String


Question: Reverse Words in a String

Given an input string, reverse the string word by word.

For example,
Given s = "the sky is blue",
return "blue is sky the".

Clarification:

  • What constitutes a word?
    A sequence of non-space characters constitutes a word.
  • Could the input string contain leading or trailing spaces?
    Yes. However, your reversed string should not contain leading or trailing spaces.
  • How about multiple spaces between two words?
    Reduce them to a single space in the reversed string.

思路:每个单词按顺序翻转,组合每个单词,对组合的句子再翻转。

例子: s = "ab cd"

<1>s的单词翻转后是"ba dc",记为_s

<2>将_s再翻转后是"cd ab"

优质内容筛选与推荐>>
1、[jQuery]使用jQuery.Validate进行客户端验证——不使用微软验证控件的理由-目录及简介
2、字典树(前缀树)
3、CI框架Email类发送邮件提示Unable to send data: . The following SMTP error was encountered: Unable to .......
4、Yii framwork crud 命名范围NAMED SCOPE 笔记四
5、Ubuntu切换显卡


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号