Skip to content

Commit 2488680

Browse files
committed
DaleStudy#220 valid-palindrome solution
1 parent 3dc6c7d commit 2488680

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

โ€Žvalid-palindrome/sungjinwi.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
ํ’€์ด :
3+
alnum์ธ ๋ฌธ์ž๋“ค๋งŒ ์ถ”์ถœํ•ด์„œ ์†Œ๋ฌธ์ž๋กœ ๋งŒ๋“ค์–ด alnu_s๋ฅผ ๋งŒ๋“ฌ
4+
์–‘ ๋์ด ๊ฐ™์€ ๋ฌธ์ž์ผ ๋™์•ˆ left++, right-- ์‹ค์‹œ
5+
๊ฐ™์ง€ ์•Š์œผ๋ฉด false, ์–‘ ๋์ด ์ˆ˜๋ ด๋˜์„œ ์„œ๋กœ ๋งŒ๋‚œ๋‹ค๋ฉด true
6+
7+
๋ฌธ์ž ๊ธธ์ด N
8+
9+
TC : O(N)
10+
11+
SC : O(N)
12+
*/
13+
14+
#include <string>
15+
using namespace std;
16+
17+
class Solution {
18+
public:
19+
bool isPalindrome(string s) {
20+
string alnu_s = "";
21+
22+
for (char c : s)
23+
{
24+
if (isalnum(c))
25+
alnu_s += tolower(c);
26+
}
27+
int left = 0;
28+
int right = alnu_s.size() - 1;
29+
while (left < right)
30+
{
31+
if (alnu_s[left] != alnu_s[right])
32+
return false;
33+
left++;
34+
right--;
35+
}
36+
return true;
37+
}
38+
};

0 commit comments

Comments
ย (0)