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 05c0932 commit 138a294Copy full SHA for 138a294
valid-palindrome/flynn.cpp
@@ -0,0 +1,36 @@
1
+/**
2
+ * 풀이
3
+ * - 주어진 string `s`의 양 끝에서부터 차례대로 비교해가며 palindrome 여부를 판단합니다
4
+ *
5
+ * Big-O
6
+ * - N: 주어진 string `s`의 길이
7
8
+ * - Time Complexity: O(N)
9
+ * - `s`가 palindrome인 경우, `s` 전체를 탐색하므로 O(N)의 시간복잡도를 가집니다
10
11
+ * - Space Complexity: O(1)
12
+ * - 입력값과 무관하게 일정한 저장공간을 사용합니다
13
+ */
14
+
15
+class Solution {
16
+public:
17
+ bool isPalindrome(string s) {
18
+ string::iterator lo = s.begin();
19
+ string::iterator hi = s.end();
20
21
+ while (lo <= hi) {
22
+ if (isalnum(*lo) && isalnum(*hi)) {
23
+ if (tolower(*lo) != tolower(*hi)) return false;
24
+ else {
25
+ ++lo;
26
+ --hi;
27
+ continue;
28
+ }
29
30
+ if (!isalnum(*lo)) ++lo;
31
+ if (!isalnum(*hi)) --hi;
32
33
34
+ return true;
35
36
+};
0 commit comments