Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 프로그래머스
- 백준
- 프로그래머스 파이썬
- 코로나19
- programmers
- ChatGPT
- ubuntu
- 파이썬
- Git
- 자연어처리
- PYTHON
- leetcode
- hackerrank
- Real or Not? NLP with Disaster Tweets
- Kaggle
- 편스토랑 우승상품
- github
- SW Expert Academy
- 맥북
- 편스토랑
- dacon
- 데이콘
- gs25
- 더현대서울 맛집
- Baekjoon
- 캐치카페
- AI 경진대회
- Docker
- 금융문자분석경진대회
- 우분투
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 58. Length of Last Word (Python) 본문
728x90
반응형
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string.
If the last word does not exist, return 0.
Note: A word is defined as a maximal substring consisting of non-space characters only.
Example:
Input: "Hello World"
Output: 5
Solution
class Solution:
def lengthOfLastWord(self, s: str) -> int:
words = s.split(' ')
print(words)
word = [w for w in words if w != '']
if len(word) == 0:
answer = 0
else:
word = word[-1]
answer = len(word)
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[HackerRank] Dictionaries and Hashmaps: Two Strings (Python) (0) | 2020.03.14 |
---|---|
[HackerRank] Arrays: Array Manipulation (Python) (0) | 2020.03.13 |
[HackerRank] Arrays: Minimum Swaps 2 (Python) (0) | 2020.03.11 |
[HackerRank] Sorting: Bubble Sort (Python) (0) | 2020.03.10 |
[HackerRank] Jumping on the Clouds (Python) (0) | 2020.03.09 |
Comments