leetcode 151   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".

python代码:

class Solution(object):def reverseWords(self, s):""":type s: str:rtype: str"""rs=s[::-1] #将整个字符串反转l=rs.split() #将反转后的字符串通过split()函数进行分割,产生的单词发在列表l中ls=[word[::-1] for word in l] #使用列表解析,反转列表l中的每一个单词return ' '.join(ls)  #使用join()函数,将列表ls中的单词,通过空格连接成一个字符串

(完)

leetcode 151 Reverse Words in a String (python)相关推荐

  1. LeetCode 151. Reverse Words in a String

    151. Reverse Words in a String Given an input string, reverse the string word by word. For example, ...

  2. leetcode 557. Reverse Words in a String III 、151. Reverse Words in a String

    557. Reverse Words in a String III 最简单的把空白之间的词反转 class Solution { public:string reverseWords(string ...

  3. leetcode day1 -- Reverse Words in a String Evaluate Reverse Polish Notation Max Points on a Li

    以前从来没做过什么oj,发现做oj和在本地写代码或者纸上写差别还是很大的,觉得今天开始刷oj,特此记录一下. 1.Reverse Words in a String Given an input st ...

  4. Python [Leetcode 345]Reverse Vowels of a String

    题目描述: Write a function that takes a string as input and reverse only the vowels of a string. Example ...

  5. LeetCode 345. Reverse Vowels of a String

    题目: Write a function that takes a string as input and reverse only the vowels of a string. Example 1 ...

  6. LeetCode 557. Reverse Words in a String III

    题目 : Given a string, you need to reverse the order of characters in each word within a sentence whil ...

  7. LeetCode OJ1:Reverse Words in a String

    问题描述: Given an input string, reverse the string word by word. For example, Given s = "the sky i ...

  8. Leetcode 345: Reverse Vowels of a String

    问题描述: Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', ...

  9. 151. Reverse Words in a String

    1 题目理解 输入:一个字符串s 规则:一个单词是一串非空字符组成的.单词之间用空格分隔. 输出:将字符串按照单词反转字符串.多余的空格只保留一个. Example 1: Input: s = &qu ...

最新文章

  1. No.3 clojure 调用 Java
  2. 花了2周时间收集汇总的大厂面经,节后准备跳槽的看过来!
  3. 替换ExpandableListView右边箭头Group Indicator(小图标)
  4. 数据结构与算法之二叉树的先序遍历,中序遍历,后序遍历
  5. ORACLE基础应用学习-- 各种故障的恢复方法总结
  6. 【剑指offer】面试题32 - II:从上到下打印二叉树 II(Java)
  7. 重构随笔——重构的原则
  8. minio 搭建blob
  9. Kafka AKHQ 安装部署
  10. matlab nist接口文件,Matlab调用refprop教程说明
  11. 水晶报表客户机电脑报错“CrystalDecisions.CrystalReports.Engine.ReportDocument”
  12. 机器学习实战(SVM)
  13. 安装此计算机程序代码18,我安装VS15,运行程序代码的时候显示的是计算机丢失msv...
  14. Scratch编程入门
  15. 工业4.0,智能制造和大规模定制
  16. 昆山花桥房都要上万 上海买家占9成“江山”
  17. 人生性格、爱情与酒场哲学
  18. Unity3D 中LookAt()方法
  19. Java基础(一)Java语言概述及入门
  20. 前端低代码平台腾讯云微搭使用文档

热门文章

  1. 内存地址、机器码与汇编指令的三角恋关系
  2. python士兵突击_03_士兵开火
  3. Github快速下载方法
  4. 华为服务器 联想服务器 稳定性,西安华为服务器
  5. DPDK中文-DPDK工具(pdump)
  6. 朝作猛虎行,暮作猛虎吟。C和C++的区别和联系
  7. 主板EC程序烧写异常致无法点亮修复经验
  8. 一、E - A + B
  9. Web安全1.3:Arachni扫描器安装、Burpsuit激活及https证书的导入
  10. 制作项目——坦克大战