298. Reverse Characters in Each Word of String
Reverse Characters in Each Word of String
Given a sentence s, reverse the characters of every word while preserving the original word order and spaces.

Method Signature

String reverseWords(String s)
  • s is the sentence whose words must be reversed.
  • Return the sentence after reversing the characters within each word.

Constraints

  • 1 <= s.length() <= 50,000
  • s contains only printable ASCII characters.
  • s has no leading or trailing spaces.
  • s contains at least one word.
  • Adjacent words are separated by exactly one space.

Examples

Example 1

Method call: reverseWords(s = "Code builds skill")
Output: "edoC sdliub lliks"

Example 2

Method call: reverseWords(s = "Hello World")
Output: "olleH dlroW"


Please use Laptop/Desktop or any other large screen to add/edit code.