728x90
1.문제

2.풀이
공백을 기준으로 split 메소드를 사용하면 간단한 문제!
3.코드
class Solution:
def lengthOfLastWord(self, s: str) -> int:
last_word = s.split()[-1]
# print(last_word)
return len(last_word)728x90
'코딩 테스트' 카테고리의 다른 글
| [LeetCode] Find the Index of the First Occurrence in a String (Python) (0) | 2025.01.15 |
|---|---|
| [LeetCode] 14.Longest Common Prefix (Python) (0) | 2025.01.15 |
| [LeetCode] Roman to Integer (0) | 2025.01.14 |
| [LeetCode] In Subsequence (Python) (0) | 2025.01.13 |
| [프로그래머스] 6주차 - 복서 정렬하기 (C++) (0) | 2021.09.08 |