Skip to content

Commit 5e7ea55

Browse files
authored
Merge pull request #1779 from mkwkw/main
[mkwkw] WEEK 03 solutions
2 parents fb930e4 + bfe9a6a commit 5e7ea55

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

combination-sum/mkwkw.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//set-up

number-of-1-bits/mkwkw.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//set-up

valid-palindrome/mkwkw.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(string s) {
4+
5+
string str = "";
6+
7+
for(int i=0; i<s.length(); i++)
8+
{
9+
if(isalpha(s[i]))
10+
{
11+
str += tolower(s[i]);
12+
}
13+
else if (s[i]>='0' && s[i]<='9') //alpha"numeric"
14+
{
15+
str += s[i];
16+
}
17+
}
18+
19+
//Palindrome
20+
if(s.length()==0 || s.length()==1)
21+
{
22+
return true;
23+
}
24+
25+
for(int i=0; i<str.length()/2; i++)
26+
{
27+
if(str[i]!=str[str.length()-1-i])
28+
{
29+
return false;
30+
}
31+
}
32+
33+
return true;
34+
}
35+
};

0 commit comments

Comments
 (0)