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
- 프로그래머스 파이썬
- hackerrank
- 프로그래머스
- gs25
- Kaggle
- 우분투
- 데이콘
- github
- Git
- PYTHON
- 백준
- dacon
- 맥북
- Baekjoon
- Docker
- ChatGPT
- 편스토랑 우승상품
- 더현대서울 맛집
- 코로나19
- SW Expert Academy
- Real or Not? NLP with Disaster Tweets
- ubuntu
- 편스토랑
- 파이썬
- programmers
- AI 경진대회
- 자연어처리
- 금융문자분석경진대회
- leetcode
- 캐치카페
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


SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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 |