# 01. 유효한 팰린드롬(leetcode: 125)

{% hint style="info" %}
[**정규표현식 패턴**](https://brownbears.tistory.com/62)

[**점프 투 파이썬 정규표현식**](https://wikidocs.net/4308)

[**re**](https://app.gitbook.com/s/-MO1zujRJyNAUnlhg0GB/undefined/undefined-1/ggdocs.python.org/3/library/re.html#re.sub)

[**re sub**](https://docs.python.org/3/library/re.html#re.sub)

[**문제링크**](https://leetcode.com/problems/valid-palindrome/)
{% endhint %}

### 풀이

문제를 보면 `considering only alphanumeric and character and ignoring cases` 라는 조건이 있다.

따라서 인자로 받은 문자열 s 에 조작을 가해서 영어, 숫자로 만드는 작업이 필요함.

1. 정규표현식 `re` 모듈을 이용해서 원하지 않는 문자들을 없애자
2. 소문자로 만들자
3. 이후에는 `deque` 를 이용해서 앞과 뒤를 하나씩 `pop` 하면서 조사

```python
# re.sub(pattern, repl, string, count=0, flags=0)
s = re.sub([^A-Za-z0-9], "", s).lower()
```

```python
deq = collections.deque(s.lower())
while len(deq) > 1:
  if deq.popleft() != deq.pop():
    return False
  return True
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://simian114.gitbook.io/blog/undefined/undefined-1/01.-leetcode-125.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
