python-algorithm
leetcode 58. Length of Last Word
무적김두칠
2023. 1. 21. 23:42
https://leetcode.com/problems/length-of-last-word/description/
Length of Last Word - LeetCode
Length of Last Word - Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only. Example 1: Input: s = "Hello World" Output: 5 Explanation: Th
leetcode.com
1
2
3
4
|
class Solution:
def lengthOfLastWord(self, s: str) -> int:
answer = len(s.split()[-1])
return answer
|
cs |
반응형