leetcode刷题记录--Reverse String

题目

难度:easy

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

Example:

Given s = "hello", return "olleh".

第一次解法

/**
 * @param {string} s
 * @return {string}
 */
var reverseString = function(s) {
    let l = s.length
    let res = ''
    while(l>0){
        res += s.charAt(l-1)
        l--
    }
    return res
};# runtime : 80ms

你可能感兴趣的:(leetcode刷题记录--Reverse String)