Skip to content

Commit e8ae68c

Browse files
committed
Solve one Leetcode Problem
1 parent 3aac6fc commit e8ae68c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

5_Basic_Recursion/intro.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,34 @@ int fibonacciOfN(int n)
163163
return fibonacciOfN(n - 1) + fibonacciOfN(n - 2);
164164
}
165165

166+
// Leetcode 125. Valid Palindrome
167+
bool isPalindrome(string s)
168+
{
169+
int start = 0;
170+
int end = s.size() - 1;
171+
while (start <= end)
172+
{
173+
if (!isalnum(s[start]))
174+
{
175+
start++;
176+
continue;
177+
}
178+
if (!isalnum(s[end]))
179+
{
180+
end--;
181+
continue;
182+
}
183+
if (tolower(s[start]) != tolower(s[end]))
184+
return false;
185+
else
186+
{
187+
start++;
188+
end--;
189+
}
190+
}
191+
return true;
192+
}
193+
166194
int main()
167195
{
168196
int n;

0 commit comments

Comments
 (0)