嗨, 大家好: 网站在新年后正式开通,欢迎大家加入我们,共同维护一个良好氛围的中国技术社区。 欢迎举报不良帖子,欢迎提供建议。
我们的QQ群:136102234,欢迎进群找答案,里边会有很多资深的大师们。 point overflow

一个好玩的手写代码网站

有个题目是反转字符串。

但是会有时间等要求。

一下是个人尝试过的方式。

asked 2016-06-22 17:24:30

jkant's gravatar image

jkant ♦♦
11133138139
accept rate: 3%


最终方式能想到的也是自己试过比较快的:

class Solution(object): def reverseString(self, s): """ :type s: str :rtype: str """ if len(s)<=1 : return s else: l=list(s) l.reverse() return ''.join(l)

link

answered 2016-06-22 17:25:21

jkant's gravatar image

jkant ♦♦
11133138139
accept rate: 3%

其他方式:

1.for 循环后从结尾获取:循环的方式肯定是通不过的

2.pop 方式

3.首尾位置互换:也有循环

link

answered 2016-06-22 17:27:22

jkant's gravatar image

jkant ♦♦
11133138139
accept rate: 3%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×10
×1

Asked: 2016-06-22 17:24:30

Seen: 1,878 times

Last updated: 2016-06-22 17:27:22