code >>
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
class Solution {
public:
bool validPalindrome(string s) {
int strlen = (int)s.size();
int i = 0;
int j = strlen - 1;
if (j == 0)
return true;
while (j >= 0 && i < strlen)
{
if ((s[j] != s[i]))
{
string temp1 = s;
temp1.erase(i,1);
string temp2 = s;
temp2.erase(j, 1);
bool result1 = this->deletedPalindrome(temp1);
bool result2 = this->deletedPalindrome(temp2);
if ((result1) || (result2))
return true;
else
return false;
}
else
{
j--;
i++;
}
}
return true;
}
bool deletedPalindrome(string s)
{
int strlen = (int)s.size();
int i = 0;
int j = strlen - 1;
if (j == 0)
return true;
while (j >= 0 && i < strlen)
{
if ((s[j] != s[i]))
{
return false;
}
else
{
j--;
i++;
}
}
return true;
}
};
|
'C' 카테고리의 다른 글
c++ leetcode 49 Group Anagrams solutions code (0) | 2021.07.07 |
---|---|
c++ leetcode 415 AddStrings solution (0) | 2021.07.06 |
c++ leetcode 125 valid palindrome solution (0) | 2021.07.06 |
c++ Rabin-Kaap 알고리즘을 활용한 leetcode 796번 Rotate String (O(N)) (0) | 2021.07.06 |
c++ 문자열 검색 O(N)으로 하기 with Rabin-Karp 알고리즘 (0) | 2021.07.05 |