Skip to content

Commit 37bd334

Browse files
longsizhuogithub-actions[bot]
authored andcommitted
chore(docs): sync doc metadata [skip ci]
1 parent a8cd6a1 commit 37bd334

File tree

2 files changed

+51
-32
lines changed

2 files changed

+51
-32
lines changed

app/docs/CommunityShare/Leetcode/2131. 连接两字母单词得到的最长回文串.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
title: 2131. 连接两字母单词得到的最长回文串.md
3-
date: '2025/5/25-2:33'
3+
date: "2025/5/25-2:33"
44
tags:
55
- - Python
66
- - Answer
77
abbrlink: 9fa195e5
8+
docId: ksw2vic4alf1tdnnueay81g8
89
---
910

1011
# QUESTION:
@@ -34,18 +35,18 @@ Example:
3435

3536
5. Second "gg" finds "gg" exists → use "gg" + "gg" as a pair → res += 4 → map becomes { "lc": 0, "gg": 0 }
3637

37-
Then we check whether the hash map contains any palindromic word (i.e., a word with two identical characters) that can be used as the center of the final palindrome string.
38-
If such a word exists, we can add 2 more to the result.
38+
Then we check whether the hash map contains any palindromic word (i.e., a word with two identical characters) that can be used as the center of the final palindrome string.
39+
If such a word exists, we can add 2 more to the result.
3940

4041
6. Finding a center word (can only pick one symmetric word)
41-
⚠️ In this example, all "gg" words have been paired, so none is left → no center word is added.
42-
42+
⚠️ In this example, all "gg" words have been paired, so none is left → no center word is added.
4343

4444
思路来自ling-nc大佬. 构建哈希表,统计每个单词的出现次数。
4545

4646
对于每个单词,检查其逆序是否存在于哈希表中,如果存在,则可以形成一个回文串,更新结果并减少对应的计数。
4747
如果逆序不存在,则将该单词的计数增加。最后检查是否有可以作为中心的回文单词。
4848
举例:
49+
4950
1. 输入 ["lc", "cl", "gg", "gg"]
5051

5152
2. "lc" 没有配对 → 存入 map: { "lc": 1 }
@@ -55,10 +56,11 @@ Example:
5556
4. "gg" 没有配对 → 存入 map: { "lc": 0, "gg": 1 }
5657

5758
5. 第二个 "gg" 发现 "gg" 存在 → 成对使用 "gg"+"gg" → res += 4 → map: { "lc": 0, "gg": 0 }
58-
接着检查哈希表中是否有可以作为中心的回文单词(即两个字母相同的单词),如果有,则可以增加2到结果中。
59+
接着检查哈希表中是否有可以作为中心的回文单词(即两个字母相同的单词),如果有,则可以增加2到结果中。
5960

6061
6. 第二部分:寻找中间部分(只能选一个对称字符串)
61-
⚠️ 在这个例子中,"gg" 都被配完了,没剩下 → 不会加中间部分。
62+
⚠️ 在这个例子中,"gg" 都被配完了,没剩下 → 不会加中间部分。
63+
6264
# Code:
6365

6466
```python
@@ -83,28 +85,28 @@ class Solution:
8385

8486
```typescript
8587
function longestPalindrome(words: string[]): number {
86-
const count: Map<string, number> = new Map();
87-
let res = 0;
88-
89-
for (const word of words) {
90-
const reversed = word.split('').reverse().join('');
91-
const reversedCount = count.get(reversed) ?? 0;
92-
93-
if (reversedCount > 0) {
94-
count.set(reversed, reversedCount - 1);
95-
res += 2 * word.length;
96-
} else {
97-
count.set(word, (count.get(word) ?? 0) + 1);
98-
}
88+
const count: Map<string, number> = new Map();
89+
let res = 0;
90+
91+
for (const word of words) {
92+
const reversed = word.split("").reverse().join("");
93+
const reversedCount = count.get(reversed) ?? 0;
94+
95+
if (reversedCount > 0) {
96+
count.set(reversed, reversedCount - 1);
97+
res += 2 * word.length;
98+
} else {
99+
count.set(word, (count.get(word) ?? 0) + 1);
99100
}
101+
}
100102

101-
for (const [word, freq] of count.entries()) {
102-
if (word === word.split('').reverse().join('') && freq > 0) {
103-
res += word.length;
104-
break; // 只能选一个居中的回文串
105-
}
103+
for (const [word, freq] of count.entries()) {
104+
if (word === word.split("").reverse().join("") && freq > 0) {
105+
res += word.length;
106+
break; // 只能选一个居中的回文串
106107
}
108+
}
107109

108-
return res;
110+
return res;
109111
}
110-
```
112+
```

generated/doc-contributors.json

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"repo": "InvolutionHell/involutionhell",
3-
"generatedAt": "2025-11-30T03:06:24.054Z",
3+
"generatedAt": "2025-12-01T03:07:26.387Z",
44
"docsDir": "app/docs",
5-
"totalDocs": 128,
5+
"totalDocs": 129,
66
"results": [
77
{
88
"docId": "ue27z7z95yzw3lhhfj7nit1c",
@@ -2136,6 +2136,23 @@
21362136
}
21372137
]
21382138
},
2139+
{
2140+
"docId": "ksw2vic4alf1tdnnueay81g8",
2141+
"path": "app/docs/CommunityShare/Leetcode/2131. 连接两字母单词得到的最长回文串.md",
2142+
"contributorStats": {
2143+
"114939201": 1
2144+
},
2145+
"contributors": [
2146+
{
2147+
"githubId": "114939201",
2148+
"contributions": 1,
2149+
"lastContributedAt": "2025-12-01T03:00:37.000Z",
2150+
"login": "longsizhuo",
2151+
"avatarUrl": "https://avatars.githubusercontent.com/u/114939201?v=4",
2152+
"htmlUrl": "https://github.com/longsizhuo"
2153+
}
2154+
]
2155+
},
21392156
{
21402157
"docId": "lzrh7ftq3kegsyx8gimonrfu",
21412158
"path": "app/docs/CommunityShare/Leetcode/2241. Design an ATM Machine.md",
@@ -2293,13 +2310,13 @@
22932310
"docId": "wen0bbo8m93oih1mx6sva9sh",
22942311
"path": "app/docs/CommunityShare/Leetcode/538.把二叉搜索树转换为累加树_translated.md",
22952312
"contributorStats": {
2296-
"114939201": 1
2313+
"114939201": 2
22972314
},
22982315
"contributors": [
22992316
{
23002317
"githubId": "114939201",
2301-
"contributions": 1,
2302-
"lastContributedAt": "2025-11-30T03:00:04.000Z",
2318+
"contributions": 2,
2319+
"lastContributedAt": "2025-11-30T03:06:25.000Z",
23032320
"login": "longsizhuo",
23042321
"avatarUrl": "https://avatars.githubusercontent.com/u/114939201?v=4",
23052322
"htmlUrl": "https://github.com/longsizhuo"

0 commit comments

Comments
 (0)