Skip to content

docs: add a description of the solution to lc problem: No.0409 #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions solution/0400-0499/0409.Longest Palindrome/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@

<!-- 这里可写通用的实现逻辑 -->

> 一个回文字符串,最多存在一个出现奇数次数的字符,

先统计所有字符出现的次数,通用的方式是哈希表。题目已说明只存在大小写字母(52 种可能),也可以使用数组来存储。

而后,可分两种方式:

- 布尔变量
- 累加出现次数为偶数的数值。
- 对于奇数,第一次出现,完整累加;后续出现,则需要对次数 `-1` 去奇,再累加。
- 计数器
- 记录奇数出现的次数,最后的结果回文长度由 `s.length - count` 得知。
- 如果只存在一个奇数,那么可以直接返回 `s.length`.

<!-- tabs:start -->

### **Python3**
Expand Down