Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 중간
- binary search
- HashTable
- dfs
- 쉬움
- Array
- backtracking
- leetcode
- hash table
- linked list
- 문자열
- tree
- easy
- recursive
- Depth-first Search
- sorting
- matrix
- 미디움
- string
- list
- 리트코드
- 이진트리
- Binary
- two pointers
- Python
- DP
- binary tree
- math
- 재귀
- Medium
Archives
- Today
- Total
목록2023/11/07 (1)
부부의 코딩 성장 일기
LeetCode 58(Length of Last Word, Python)
1. 문제 링크 https://leetcode.com/problems/length-of-last-word/ 2. 문제 설명 단어와 공백으로 구성된 문자열 s가 주어졌을 때, 가장 마지막 단어의 길이를 반환 예시) s = "Hello World", output: 5 (마지막 단어인 "World"의 길이 5 반환) 3. 처음 풀이 문자열에 대한 관련 함수를 이미 알고 있어서, 간단하게 해결. s의 양쪽 공백을 없애고, ' ' 기준 split을 한 후, 마지막 element의 lenght를 반환 class Solution: def lengthOfLastWord(self, s: str) -> int: return len(s.strip().split(' ')[-1]) # 양 쪽 공백을 없애고, ' '기준으로 s..
Algorithm/LeetCode
2023. 11. 7. 19:00