> For the complete documentation index, see [llms.txt](https://simian114.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://simian114.gitbook.io/blog/undefined/undefined-1/01.-leetcode-125.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
