Advertisement
YeetMaster69

Leetcode 115

May 12th, 2022
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. class Solution:
  2.     def numDistinct(self, s: str, t: str) -> int:
  3.         @lru_cache(None)
  4.         def solve(i,j):
  5.             if j>=len(t): return 1
  6.             elif i>=len(s): return 0
  7.             ans = 0
  8.             if s[i] == t[j]:
  9.                 ans += solve(i+1,j+1) + solve(i+1,j)
  10.             else:
  11.                 ans += solve(i+1,j)
  12.             return ans
  13.         return solve(0,0)
  14.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement