美文网首页
leetcode刷题记录--Reverse String

leetcode刷题记录--Reverse String

作者: fishliu | 来源:发表于2018-01-14 16:16 被阅读0次

题目

难度: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

      本文链接:https://www.haomeiwen.com/subject/hpgkoxtx.html