카테고리 없음
LeetCode 115. Distinct Subsequences
Sssspinach
2023. 2. 26. 19:45
# recursion
class Solution:
ret = 0
def numDistinct(self, s: str, t: str) -> int:
def rec(s1, t1):
if not t1:
self.ret += 1
return
if not s1:
return
for i in range(len(s1)):
if s1[i] == t1[0] and len(s1) - i >= len(t1):
rec(s1[i+1:], t1[1:])
rec(s,t)
return self.ret
=> 시간 초과
재귀 코드는 시간 복잡도를 어떻게 계산하는지 아직 잘 모르겠다.