1451. Rearrange Words in a Sentence

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1451

class Solution:
    def arrangeWords(self, text: str) -> str:
        words = text.split()
        words[0] = words[0].lower()
        words.sort(key=len)
        words[0] = words[0].title()
        return " ".join(words)