728x90
1월 9일 daily 문제
난이도 : easy
접두사로 pref를 가진 것을 words라는 리스트 내에 몇 개 있는지 찾는 문제
class Solution(object):
def prefixCount(self, words, pref):
"""
:type words: List[str]
:type pref: str
:rtype: int
"""
res = 0
n = len(pref)
for i in range(len(words)):
if words[i][:n] == pref:
res += 1
return res
- words[i]의 앞부분이 pref와 동일한지 확인하고 counting한 값을 return
간단한 문제인데 너무 풀어 쓴듯한 느낌이다.
Runtime : 0ms
Memory : 12.39MB (31.14%)
728x90
'코딩 공부 > Leetcode' 카테고리의 다른 글
[Python] 412. Fizz Buzz (0) | 2025.01.10 |
---|---|
[Python] 2381. Shifting Letters II (0) | 2025.01.09 |
[Python] 1672. Richest Customer Wealth (0) | 2025.01.09 |
[Python] 3042. Count Prefix and Suffix Pairs I (0) | 2025.01.08 |
[Python] 1480. Running Sum of 1d Array (0) | 2025.01.08 |