Skip to content

Commit f3b9a3d

Browse files
✨ Day 3
1 parent 8f2bf11 commit f3b9a3d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## Week 1 🚧
88
1. [Detect Capital](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/549/week-1-august-1st-august-7th/3409/) ➡️ [CPP Solution](Week1/detectCapital.cpp)
99
2. [Design HashSet](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/549/week-1-august-1st-august-7th/3410/) ➡️ [CPP Solution](Week1/designHashset.cpp)
10+
3. [Valid Palindrome](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/549/week-1-august-1st-august-7th/3411/) ➡️ [CPP Solution](Week1/validPalindrome.cpp)
1011

1112
## Where to find me? 🌟
1213
* [Website](https://akashwho.codes/)

Week1/validPalindrome.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(string s) {
4+
if(s.empty() || s.size() == 1) return true;
5+
6+
int i = 0;
7+
int j = s.size() - 1;
8+
9+
while(i <= j) {
10+
while(!isalnum(s[i]) && i < j) i++;
11+
while(!isalnum(s[j]) && i < j) j--;
12+
13+
if(tolower(s[i]) != tolower(s[j])) return false;
14+
15+
i++;
16+
j--;
17+
}
18+
19+
return true;
20+
}
21+
};

0 commit comments

Comments
 (0)