Back to course home
0% completed
Vote For New Content
reversedList is pointless (in JS)
traviswlilleberg
Oct 17, 2025
/* In JavaScript (and possibly other languages), the reversedList array is pointless and creates unnecessary space overhead for the function. You can build a string directly from the stack, like so: */ class Solution { reverseString(s) { if(!s.length) { return s } const stack = s.split(''); let output = ''; while(stack.length) { output += stack.pop(); } return output; } }
0
0
Comments
Comments
On this page