코딩 공부/Leetcode
[Python] 2185. Counting Words With a Given Prefix
일하는 공학도
2025. 1. 9. 10:25
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