ALGORITHM

TIL 2021.05.07

Solved in: Javascript and Python

QUESTION

58. Length of Last Word

Given a string s consists of some words separated by spaces, return the length of the last word in the string. If the last word does not exist, return 0.

A word is a maximal substring consisting of non-space characters only.

Constraints:

  • 1 <= s.length <= 104
  • s consists of only English letters and spaces ‘ ‘.

Solution: JavaScript

Solution: Python

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store