We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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