Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool isMatch(string s, string p) {
  4.         for( int i=0 ; i<p.size() ; i++)
  5.         {
  6.             if(p[i] == '*')
  7.             {
  8.                 if(p[i-1] != '.')
  9.                     p[i-1] -= 32;
  10.                 else    p[i-1]--;
  11.                 p.erase(i, 1);
  12.                 i--;
  13.             }
  14.         }
  15.         cout << p << endl;
  16.         return check(p, s, 0, 0);
  17.     }
  18.    
  19.     bool check(string s, string p, int i, int j) {
  20.        
  21.         if(p.size() == j) return true;
  22.         if(s.size() == i) return false;
  23.          
  24.         bool result = false;
  25.  
  26.         if(s[i] >= 97)
  27.         {
  28.             if(s[i] == p[j]) result = result || check(s, p, i+1, j+1);
  29.             else return false;
  30.         }
  31.         else if(s[i] == '.')
  32.         {
  33.             result = result || check(s, p, i+1, j+1);
  34.         }
  35.         else if(s[i] == '.' - 1)
  36.         {
  37.             result = result || check(s, p, i, j+1);
  38.             result = result || check(s, p, i+1, j);
  39.         }
  40.         else  
  41.         {
  42.             if(s[i]+32 == p[j]) result = result || check(s, p, i, j+1);
  43.             result = result || check(s, p, i+1, j);
  44.         }
  45.        
  46.         return result;
  47.     }
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement