Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

反转字符串 #25

Open
Vexth opened this issue Nov 1, 2018 · 0 comments
Open

反转字符串 #25

Vexth opened this issue Nov 1, 2018 · 0 comments

Comments

@Vexth
Copy link
Owner

Vexth commented Nov 1, 2018

编写一个函数,其作用是将输入的字符串反转过来。

示例 1:

输入: "hello"
输出: "olleh"
示例 2:

输入: "A man, a plan, a canal: Panama"
输出: "amanaP :lanac a ,nalp a ,nam A"
func reverseString(s string) string {
    if len(s) == 0 {
        return s
    }
    
    as := new(bytes.Buffer)
    for i := len(s) - 1; i >= 0; i-- {
        as.WriteByte(s[i])
    }
    return as.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant