# 151-翻转字符串里的单词-中等
# 我的解答
# 官方解答
# 优质解答
[图解字节&leetcode151:翻转字符串里的单词 · Issue #18 · sisterAn/JavaScript-Algorithms (github.com) (opens new window)](https://github.com/sisterAn/JavaScript-Algorithms/issues/18)
-
var reverseWords = function(s) { let left = 0 let right = s.length - 1 let queue = [] let word = '' while (s.charAt(left) === ' ') left ++ while (s.charAt(right) === ' ') right -- while (left <= right) { let char = s.charAt(left) if (char === ' ' && word) { queue.unshift(word) word = '' } else if (char !== ' '){ word += char } left++ } queue.unshift(word) return queue.join(' ') };
← 239-滑动窗口最大值问题-难 目录 →