Question: convert python code to cpp class Solution ( object ) : def isMatch ( self , s , p ) : :type

convert python code to cpp
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
:type p: str
:rtype: bool
"""
dp =[[False]*(len(p)+1) for _ in range(len(s)+1)]
dp[0][0]= True
for j in range(1, len(p)+1):
if p[j -1]=='*':
dp[0][j]= dp[0][j -2]
for i in range(1, len(s)+1):
for j in range(1, len(p)+1):
if p[j -1]== s[i -1] or p[j -1]=='.':
dp[i][j]= dp[i -1][j -1]
elif p[j -1]=='*':
dp[i][j]= dp[i][j -2] or (dp[i -1][j] if s[i -1]== p[j -2] or p[j -2]=='.' else False)
return dp[len(s)][len(p)]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!