64. Length of the last word

EasyProgramFree10 points

A string consists of words separated by spaces, possibly with extra spaces at either end. Write lengthOfLastWord s, the number of characters in its last word.

Examples

  1. Input: lengthOfLastWord "Hello World"Output: 5
  2. Input: lengthOfLastWord " fly me to the moon "Output: 4
  3. Input: lengthOfLastWord "luffy is still joyboy"Output: 6

Submitting also runs 5 hidden tests.

Constraints

  • s contains at least one word and no characters other than letters and spaces.
Solution.lean
Loading editor…

Run checks your code against the examples and your custom inputs and records nothing. Submit also runs the hidden tests, confirms the axioms your proof uses and records the result. Each uses one compiler check.

ReadyLn 1, Col 1Lean 4
Draft saved in this browser