344. Reverse String--LeetCode Record

来源:互联网 发布:androidframework源码 编辑:程序博客网 时间:2024/05/16 14:23

Write a function that takes a string as input and returns the string
reversed.

Example: Given s = “hello”, return “olleh”.

class Solution {    func reverseString(s: String) -> String {        var strRev:String = ""        var charts:[Character] = []        for chart in s.characters {            charts.append(chart)        }        for chart in charts.reverse() {            strRev.append(chart)        }        return String(strRev)    }}
0 0
原创粉丝点击