jayati

Is Subsequence

Mar 15th, 2023
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool isSubsequence(string s, string t) {
  4.         int i=0,j=0;
  5.         bool f=false;
  6.         if(s.length()==0)
  7.         {
  8.             return true;
  9.         }
  10.         while(i<t.length() && j<s.length())
  11.         {
  12.             if(t[i]==s[j])
  13.             {
  14.                 i++;
  15.                 j++;
  16.                 f=true;
  17.             }
  18.             else
  19.             {
  20.                 i++;
  21.                 f=false;
  22.             }
  23.         }
  24.     if(f && j==s.length())
  25.     {
  26.         return true;
  27.     }
  28.     else
  29.     {
  30.         return false;
  31.     }
  32.        
  33.     }
  34. };
Advertisement
Add Comment
Please, Sign In to add comment