【LeetCode OJ】Reverse Words in a String
Problem link:
http://oj.leetcode.com/problems/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".
LeetCode OJ supports Python now!
The solution for this problem is extremely easy... What you need is only three build-in methods: string.split(), string.join(), and list.reverse().
class Solution:
# @param s, a string
# @return a string
def reverseWords(self, s):
res = s.split()
res.reverse()
return " ".join( res )
That is it...
【LeetCode OJ】Reverse Words in a String的更多相关文章
- 【LeetCode练习题】Reverse Words in a String
Reverse Words in a String Given an input string, reverse the string word by word. For example,Given ...
- 【LeetCode OJ】Word Ladder I
Problem Link: http://oj.leetcode.com/problems/word-ladder/ Two typical techniques are inspected in t ...
- 【LeetCode OJ】Palindrome Partitioning II
Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning-ii/ We solve this problem by u ...
- 【LeetCode OJ】Palindrome Partitioning
Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning/ We solve this problem using D ...
- 【LeetCode OJ】Valid Palindrome
Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Evaluate Reverse Polish Notation
Problem link: http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ According to the wik ...
- 【LeetCode OJ】Binary Tree Zigzag Level Order Traversal
Problem Link: https://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ Just BFS fr ...
- 【LEETCODE OJ】Reorder List
Problem link: http://oj.leetcode.com/problems/reorder-list/ I think this problem should be a difficu ...
随机推荐
- Ubuntu下配置和编译cpp-ethereum客户端
Ethereum,中文翻译是“以太坊”,是一个公有区块链的开源项目.因为以太坊是基于P2P网络所以没有中心节点,所以用户仅安装Ethereum客户端即可连入Ethereum公共网络或者在自己的test ...
- java.util 类 TreeSet<E>
java.lang.Object≥ java.util.AbstractCollection<E> ≥ java.util.AbstractSet<E> ≥ java.util ...
- [转载]SAP BASIS学习手册
原文地址:SAP BASIS学习手册作者:sapren 1:)要用scc4定义一个新的client,同时定义好类型(T,P,D等) 2:)用user/pasword: (sap*/pass) ...
- javascript function new this
1. 首先,我们这里把function直接调用时将这个function当做方法来看待,而new function是将function当做类来看待 2. 当把function作为类来使用时,functi ...
- PDF 补丁丁 0.4.1.839 测试版发布:调整页面留白
新的测试版的补丁功能实现了调节页面留白的功能(之前的820版尚未实现该功能),页面合并功能支持从资源管理器拖放文件或目录到列表,还修正了一些问题. 欢迎下载测试.
- ACTIVITI 源码研究之命令模式执行
ACTIVITI 是一个优秀开源软件,通过阅读源码,我们不但可以了解工作流引擎执行的原理还可以增加个人的编码功力. ACTIVITI 所有执行过程都是采用命令模式进行执行. 本文主要描述流程引擎数据保 ...
- ASP.NET文章目录导航
ASP.NET文章目录导航 ASP.NET-[读书笔记]-原创:ASP.Net状态管理读书笔记--思维导图 (2013-12-25 10:13) ASP.NET-[潜在危险]-从客户端中检测到有潜在危 ...
- Qml一些技巧
1.从ListView中获取当前选中项 myList.currentItem.children[0].text 可以获取ListView的选择项的一个个元素.注意children的使用.
- C#拉姆达(=>)表达式
前言: 之前小猪曾经分享过自己对C#委托的一点理解 其实在使用委托的过程中我们会大量的使用拉姆达(=>)表达式 介绍: "Lambda表达式"是一个匿名函数,是一种高效的类似 ...
- 使用ServerSocket创建TCP服务器端
在两个通信实体没有建立虚拟链路之前,必须有一个通信实体先做出“主动姿态”,主动接受来自其他通信实体的连接请求. Java中能接受其它通信实体连接请求的类是ServerSocket,ServerSock ...