Skip to content

Commit b23dcc4

Browse files
committed
update: 添加问题“944.删列造序”的代码和题解 (#1269)
944: AC.cpp+java+py+go+rust(#1268) + word(en) + 1problem1day cpp - WA cpp - AC,27.82%,45.86% py(oneline) - CE py(oneline) - AC,11.04%,70.13% go - AC,100.00%,38.89% java - AC,84.34%,6.03% rust - CE rust - AC,33.33%,83.33% Signed-off-by: LetMeFly666 <[email protected]>
1 parent d4eefa7 commit b23dcc4

25 files changed

+1795
-90
lines changed

.commitmsg

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
3652: AC.cpp (#1265) + word(en) + 1problem1day
1+
944: AC.cpp+java+py+go+rust(#1268) + word(en) + 1problem1day
22

3-
1problem1day from branch 3562(#1262)
3+
cpp - WA
4+
cpp - AC,27.82%,45.86%
5+
py(oneline) - CE
6+
py(oneline) - AC,11.04%,70.13%
7+
go - AC,100.00%,38.89%
8+
java - AC,84.34%,6.03%
9+
rust - CE
10+
rust - AC,33.33%,83.33%
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Add issue to 1problem1day project
2+
# 符合标题格式的issue自动添加到https://github.com/users/LetMeFly666/projects/5中
3+
# Test at https://github.com/LetMeFly666/LeetCode-test
4+
5+
on:
6+
issues:
7+
types: [opened]
8+
9+
permissions:
10+
issues: read
11+
repository-projects: write
12+
13+
env:
14+
PROJECT_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_PROJECT_ID }}
15+
DATE_FIELD_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_DATE_FIELD_ID }}
16+
17+
jobs:
18+
add:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Add issue & set Date
22+
env:
23+
GH_TOKEN: ${{ secrets.ONE_PROBLEM_ONE_DAY_PAT }}
24+
run: |
25+
title="${{ github.event.issue.title }}"
26+
issue_node_id="${{ github.event.issue.node_id }}"
27+
created_at="${{ github.event.issue.created_at }}"
28+
29+
if [[ ! "$title" =~ ^\[newSolution\]Who\ can\ add\ 1\ more\ problem\ of\ LeetCode\ [0-9]+.*$ ]]; then
30+
echo "Title not match, skip"
31+
exit 0
32+
fi
33+
34+
date_cn=$(date -d "$created_at +8 hours" +%F)
35+
36+
echo "Add issue to project"
37+
item_id=$(gh api graphql -f query='
38+
mutation($project:ID!, $content:ID!) {
39+
addProjectV2ItemById(input:{
40+
projectId:$project
41+
contentId:$content
42+
}) {
43+
item { id }
44+
}
45+
}
46+
' \
47+
-f project="$PROJECT_ID" \
48+
-f content="$issue_node_id" \
49+
--jq '.data.addProjectV2ItemById.item.id')
50+
51+
echo "Set Date field"
52+
gh api graphql -f query='
53+
mutation($project:ID!, $item:ID!, $field:ID!, $date:Date!) {
54+
updateProjectV2ItemFieldValue(input:{
55+
projectId:$project
56+
itemId:$item
57+
fieldId:$field
58+
value:{ date:$date }
59+
}) {
60+
projectV2Item { id }
61+
}
62+
}
63+
' \
64+
-f project="$PROJECT_ID" \
65+
-f item="$item_id" \
66+
-f field="$DATE_FIELD_ID" \
67+
-f date="$date_cn"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: LeetCode Daily Issue
2+
3+
# 每天北京时间0点自动创建今天的每日一题issue
4+
5+
on:
6+
schedule:
7+
- cron: '0 16 * * *' # UTC 16 = 北京 0 点
8+
workflow_dispatch:
9+
10+
permissions:
11+
issues: write
12+
13+
jobs:
14+
daily:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Fetch LeetCode daily question
18+
id: fetch
19+
run: |
20+
date=$(TZ=Asia/Shanghai date +%Y-%m-%d)
21+
year=${date:0:4}
22+
month=${date:5:2}
23+
24+
curl -s https://leetcode.cn/graphql/ \
25+
-H 'Content-Type: application/json' \
26+
-d "{
27+
\"query\":\"query dailyQuestionRecords(\$year:Int!,\$month:Int!){dailyQuestionRecords(year:\$year,month:\$month){date question{questionFrontendId titleSlug translatedTitle}}}\",
28+
\"variables\":{\"year\":$year,\"month\":$month}
29+
}" \
30+
| jq -r --arg d "$date" '
31+
.data.dailyQuestionRecords[]
32+
| select(.date==$d)
33+
| "\(.question.questionFrontendId)|\(.question.titleSlug)|\(.question.translatedTitle)"
34+
' > daily.txt
35+
36+
- name: Create issue
37+
env:
38+
GH_TOKEN: ${{ secrets.ONE_PROBLEM_ONE_DAY_PAT }}
39+
run: |
40+
IFS='|' read -r id slug title < daily.txt
41+
date=$(TZ=Asia/Shanghai date +%Y-%m-%d)
42+
43+
gh issue create \
44+
--title "[newSolution]Who can add 1 more problem of LeetCode $id" \
45+
--body "By Github Actions | [$id.$title](https://leetcode.cn/problems/$slug/) | $date" \
46+
--label 题解 \
47+
--assignee LetMeFly666 \
48+
--repo LetMeFly666/LeetCode-test
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Handle issue close
2+
# 当有issue被关闭时,自动在project中填写完成日期
3+
4+
on:
5+
issues:
6+
types: [closed]
7+
8+
permissions:
9+
issues: read
10+
repository-projects: write
11+
12+
env:
13+
PROJECT_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_PROJECT_ID }}
14+
FINISH_DATE_FIELD_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_FINISH_DATE_FIELD_ID }}
15+
16+
jobs:
17+
close:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Set finish date & done
21+
env:
22+
GH_TOKEN: ${{ secrets.ONE_PROBLEM_ONE_DAY_PAT }}
23+
run: |
24+
issue_node_id="${{ github.event.issue.node_id }}"
25+
closed_at="${{ github.event.issue.closed_at }}"
26+
date_cn=$(date -d "$closed_at +8 hours" +%F)
27+
28+
echo "Query project item_id via Issue.projectItems..."
29+
item_id=$(gh api graphql -f query='
30+
query($issue:ID!) {
31+
node(id:$issue) {
32+
... on Issue {
33+
projectItems(first:20) {
34+
nodes {
35+
id
36+
project { id }
37+
}
38+
}
39+
}
40+
}
41+
}
42+
' -f issue="$issue_node_id" \
43+
--jq ".data.node.projectItems.nodes[]
44+
| select(.project.id==\"$PROJECT_ID\")
45+
| .id")
46+
if [[ -z "$item_id" ]]; then
47+
echo "Issue not in project, skip"
48+
exit 0
49+
fi
50+
echo "Found item_id = $item_id"
51+
52+
echo "Set Finish Date field -> $date_cn"
53+
gh api graphql -f query='
54+
mutation($project:ID!, $item:ID!, $field:ID!, $date:Date!) {
55+
updateProjectV2ItemFieldValue(input:{
56+
projectId:$project
57+
itemId:$item
58+
fieldId:$field
59+
value:{ date:$date }
60+
}) {
61+
projectV2Item { id }
62+
}
63+
}
64+
' \
65+
-f project="$PROJECT_ID" \
66+
-f item="$item_id" \
67+
-f field="$FINISH_DATE_FIELD_ID" \
68+
-f date="$date_cn"
69+
echo "Set Finish Date successfully ✅"
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: Sync solving label to project status
2+
# 仅对issue增删的solving标签生效:
3+
# 添加solving标签->设置Project状态为In Progress
4+
# 移除solving标签-↓
5+
# issue为close状态->设置Project状态为Done
6+
# issue为open状态->设置Project状态为Todo
7+
# 这里GPT死活解决不了,最后分步命令之,成功了
8+
9+
on:
10+
issues:
11+
types: [labeled, unlabeled]
12+
13+
permissions:
14+
issues: read
15+
repository-projects: write
16+
17+
env:
18+
PROJECT_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_PROJECT_ID }}
19+
STATUS_FIELD_ID: ${{ secrets.ONE_PROBLEM_ONE_DAY_STATUS_FIELD_ID }}
20+
21+
jobs:
22+
sync:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Update project status by solving label
26+
env:
27+
GH_TOKEN: ${{ secrets.ONE_PROBLEM_ONE_DAY_PAT }}
28+
run: |
29+
echo "===== Event Debug ====="
30+
echo "action = ${{ github.event.action }}"
31+
echo "issue number = ${{ github.event.issue.number }}"
32+
echo "issue node_id = ${{ github.event.issue.node_id }}"
33+
echo "issue state = ${{ github.event.issue.state }}"
34+
echo "label(event) = ${{ github.event.label.name }}"
35+
echo "======================="
36+
37+
issue_node_id="${{ github.event.issue.node_id }}"
38+
issue_state="${{ github.event.issue.state }}"
39+
40+
labels="${{ join(github.event.issue.labels.*.name, ' ') }}"
41+
echo "Current labels: $labels"
42+
43+
has_solving=false
44+
for l in $labels; do
45+
[[ "$l" == "solving" ]] && has_solving=true
46+
done
47+
echo "has_solving = $has_solving"
48+
49+
echo "Query project item_id via Issue.projectItems..."
50+
item_id=$(gh api graphql -f query='
51+
query($issue:ID!) {
52+
node(id:$issue) {
53+
... on Issue {
54+
projectItems(first:20) {
55+
nodes {
56+
id
57+
project { id }
58+
}
59+
}
60+
}
61+
}
62+
}
63+
' -f issue="$issue_node_id" \
64+
--jq ".data.node.projectItems.nodes[]
65+
| select(.project.id==\"$PROJECT_ID\")
66+
| .id")
67+
if [[ -z "$item_id" ]]; then
68+
echo "Issue not in project, skip"
69+
exit 0
70+
fi
71+
echo "Found item_id = $item_id"
72+
73+
if [[ "$has_solving" == "true" ]]; then
74+
status="In Progress"
75+
else
76+
if [[ "$issue_state" == "closed" ]]; then
77+
status="Done"
78+
else
79+
status="Todo"
80+
fi
81+
fi
82+
echo "Target status name = $status"
83+
84+
echo "Resolve status option ID..."
85+
options_json=$(gh api graphql -f query='
86+
query($field:ID!) {
87+
node(id:$field) {
88+
... on ProjectV2SingleSelectField {
89+
options { id name }
90+
}
91+
}
92+
}' -F field="$STATUS_FIELD_ID")
93+
option_id=$(echo "$options_json" | jq -r --arg status "$status" '.data.node.options[] | select(.name==$status) | .id')
94+
if [[ -z "$option_id" ]]; then
95+
echo "❌ Cannot find option id for status=$status"
96+
exit 1
97+
fi
98+
echo "Resolved option_id = $option_id"
99+
100+
echo "Update project status..."
101+
if [[ "$option_id" =~ ^[0-9]+$ ]]; then
102+
echo "纯数字 -> ID!"
103+
gql_type="ID!"
104+
# 不知道为什么,这里Done的option_id为纯数字,不论ID!还是String!都不行,折腾了好久好久
105+
# 未验证这个能否用在In Progress和Todo上,感觉是可以的。保留if-else是为了保留这个神奇的Debug经历
106+
gh api graphql -f query='
107+
mutation UpdateProjectItemStatus($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
108+
updateProjectV2ItemFieldValue(
109+
input: {
110+
projectId: $projectId
111+
itemId: $itemId
112+
fieldId: $fieldId
113+
value: { singleSelectOptionId: $optionId }
114+
}
115+
) {
116+
projectV2Item {
117+
id
118+
fieldValues(first: 10) {
119+
nodes {
120+
... on ProjectV2ItemFieldSingleSelectValue {
121+
id
122+
name
123+
optionId
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
' -f projectId="$PROJECT_ID" -f itemId="$item_id" -f fieldId="$STATUS_FIELD_ID" -f optionId="$option_id"
131+
else
132+
echo "字符串 -> String!"
133+
gql_type="String!"
134+
gh api graphql -f query='
135+
mutation($project:ID!, $item:ID!, $field:ID!, $option:String!) {
136+
updateProjectV2ItemFieldValue(input:{
137+
projectId:$project
138+
itemId:$item
139+
fieldId:$field
140+
value:{ singleSelectOptionId:$option }
141+
}) {
142+
projectV2Item { id }
143+
}
144+
}
145+
' \
146+
-F project="$PROJECT_ID" \
147+
-F item="$item_id" \
148+
-F field="$STATUS_FIELD_ID" \
149+
-F option="$option_id"
150+
fi
151+
echo "Status updated successfully ✅"

0 commit comments

Comments
 (0)