leetcode刷题记录--Reverse String

2018-01-14  本文已影响0人  fishliu

题目

难度: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
上一篇 下一篇

猜你喜欢

热点阅读