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 |
반응형
'python-algorithm' 카테고리의 다른 글
백준 26560 Periods (0) | 2023.01.24 |
---|---|
leetcode 1684. Count the Number of Consistent Strings (2) | 2023.01.22 |
leetcode 2404. Most Frequent Even Element (0) | 2023.01.19 |
leetcode 2465. Number of Distinct Averages (0) | 2023.01.19 |
leetcode 2496. Maximum Value of a String in an Array (0) | 2023.01.19 |
댓글