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.
Example 1:
Input: s = "Hello World"
Output: 5Example 2:
Input: s = " "
Output: 0Constraints:
1 <= s.length <= 104sconsists of only English letters and spaces' '.
# @lc code=start
using LeetCode
length_of_last_word(s::String) = length(rsplit(s, ' '; limit = 2, keepempty=false)[end])
# @lc code=endlength_of_last_word (generic function with 1 method)
This page was generated using DemoCards.jl and Literate.jl.