package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev

# README

151. Reverse Words in a String

Solution idea

Two Pointers

  • Step 1: remove leading spaces, trailing spaces, and extra spaces betweeen words

  • Step 2a: reverse all characters all at once. 一整个字符串翻转

  • Step 2b: reverse all chars per word. 每个词每个词单独翻转

Time complexity = $O(n^2)$

Resource

代码随想录-151.翻转字符串里的单词