Leetcode: reverse words in a string
来源:互联网 发布:神户制钢造假 知乎 编辑:程序博客网 时间:2024/05/22 00:45
http://oj.leetcode.com/problems/reverse-words-in-a-string/
class Solution:
# @param s, a string
# @return a string
def reverseWords(self, s):
return ' '.join(s.split()[::-1])
这道题目挺简单,但有一点值得学习,那就是reverse string(list)的不同方式效率并不一样。
详见:http://stackoverflow.com/questions/931092/reverse-a-string-in-python
其中string/list[::-1]是最快的一个。但用其他的方式也能通过OJ。
0 0
- Leetcode - string - Reverse Words in a String
- Reverse words in a String leetcode
- [LeetCode]Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- Reverse Words in a String (LeetCode)
- LeetCode Reverse Words in a String Total
- LeetCode(151)Reverse Words in a String
- Reverse Words in a String -- LeetCode
- leetcode Reverse Words in a String
- LeetCode OJ:Reverse Words in a String
- LeetCode Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- [Leetcode] Reverse Words in a String
- Reverse Words in a String[LeetCode]
- LeetCode OJ :Reverse Words in a String
- Leetcode: Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- sencha touch笔记(11)——localstorage实现本地收藏功能以及图标的变换
- 黑马程序员 java交通灯随笔
- QEMU 的 CPU 配置
- Bloomberg面经
- Palindrome Partitioning
- Leetcode: reverse words in a string
- 如何计算时间复杂度
- Auto Rebuild Indexes
- Copy List with Random Pointer -- LeetCode
- Leetcode: Evaluate Reverse Polish Notation
- Binary Tree Inorder Traversal
- Linux下Vnc远程桌面Server配置教程
- android,中心旋转
- Populating Next Right Pointers in Each Node