We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3dc6c7d commit 2488680Copy full SHA for 2488680
โvalid-palindrome/sungjinwi.cpp
@@ -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