Programming Question : Leetcode 10
Approach for solving leetcode question 10 — Regular Expression Matching
- I solved this question with recursive approach , base case will be if there is no pattern i.e. pattern is exhausted then check whether the string is available or not , and return the boolean value accordingly.
- calculate starting match by comparing first letter of pattern , it can be a dot(.) or same as starting letter of string.
- then if there is a star in pattern, so we will have two options either use the variable or ignore it. So if we are ignoring the variable then we will have to start the pattern form 3rd character(or ignore first two characters). or if we do not want to ignore star, then we have to keep the pattern same and string will start from after first character.
- or else we have to match first character of both pattern and string and call the function recursively.