【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 ...
随机推荐
- WindowsService(Windows服务)开发步骤附Demo 【转】
转http://www.cnblogs.com/moretry/p/4149489.html 1.打开VS,新建项目,选择Windows服务,然后设置目录及项目名称后点击确定. 2.展开Service ...
- 超实用的JavaScript代码段 Item4 --发送短信验证码
发送短信验证码 实现点击“发送验证码”按钮后,按钮依次显示为“59秒后重试”.“58秒后重试”…直至倒计时至0秒时再恢复显示为“发送验证码”.在倒计时期间按钮为禁用状态 . 第一步.获取按钮.绑定事件 ...
- C#类和成员的修饰符
C#中public.private.protected.internal.protected internal & (2010-09-22 13:33:45)转载 标签: 杂谈 分类: C# ...
- SQL Server数据库(SQL Sever语言 函数以及SQL编程)
1.数学函数:操作一个数据,返回一个结果 --去上限: ceiling ☆select ceiling(price) from car --去下限:floor ☆select floor(price) ...
- backbonejs中的模型篇(三)
一:在模型中使用嵌套属性 Backbone的扩展插件 Backbone-Nested下载并添加引用 1:定义一个新的模型对象,使用Backbone.NestedModel作为其基类对象 var _mo ...
- 超棒的响应式设计测试书签和工具(bookmarks)(转)
一.测试书签(bookmarks) Viewport Resizer 这个书签号称拥有158个国家3万多活跃的用户,主要特性: 完全自定制 方便的添加自定义尺寸 手动的横竖屏切换 自动的横竖屏切换 ( ...
- The APR based Apache Tomcat Native library 异常解决办法
tomat在linux服务器上启动报The APR based Apache Tomcat Native library which allows optimal performance in pro ...
- quartz Web项目基础最简单配置
web方面的quartz 配置资料,从网上搜索出来的很难找到完整可用的代码样例.自己上传一个. IDE:Intellij tomcat jdk1.7 quartz 2.1.5 这里下载: http:/ ...
- springmvc 配置直接访问页面
<mvc:view-controller path="/" view-name="/home"/> 在mvc中配置,访问路径就可以了
- bzoj 2661: [BeiJing wc2012]连连看
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #inclu ...