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