344. Reverse String--LeetCode Record

Tong_hdj發表於2016-07-04

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)

    }
}

相關文章