Traverse the string s in reverse order, appending each element to the new string, which you then return.
def reverse_string(s) rev_s = "" (s.length - 1).downto(0).each do |i| rev_s << s[i] end rev_s end
Time complexity: O(n)
Space complexity: O(n)
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.