forked from Astha369/CPP_Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem26.cpp
37 lines (32 loc) · 795 Bytes
/
Problem26.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
bool isSubstring(string str, string substr) {
size_t found = str.find(substr);
return (found != string::npos);
}
bool isSubsequence(string str, string subseq) {
int i = 0, j = 0;
while (i < str.size() && j < subseq.size()) {
if (str[i] == subseq[j]) {
j++;
}
i++;
}
return (j == subseq.size());
}
bool isPalindrome(string str) {
int left = 0;
int right = str.size() - 1;
while (left < right) {
if (str[left] != str[right]) {
return false;
}
left++;
right--;
}
return true;
}
};