Skip to content

Commit 3c28c21

Browse files
author
lucifer
committed
feat: d2
1 parent 2bc02f2 commit 3c28c21

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

routes/dailyProblem.js

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,45 @@ const { decrypt } = require("../utils/crypto");
55
const { success } = require("../utils/request");
66

77
router.get("/api/v1/daily-problem", async (ctx) => {
8-
// 1. 获取当前时间
9-
// 2. 根据当前时间和活动开始时间计算当前是 Day 几
8+
// 1. 如果用户指定了时间,则获取指定时间,否则获取今天
9+
// 2. 根据上一步计算的时间和活动开始时间计算当前是 Day 几
1010
// 3. 根据 Day 几 计算出具体返回哪一个题目
1111

12-
ctx.body = success({
13-
day: 1,
14-
title: "66. 加一",
15-
whys: [
16-
"1. 由于是大家第一次打卡,因此出一个简单题。虽然是简单题,但是如果将加 1 改为加任意的数字,那么就变成了一个非常常见的面试题",
17-
],
18-
link: "https://leetcode-cn.com/problems/plus-one",
19-
tags: ["基础篇", "数组"], // 目前所有 README 都是没有的。因此如果没有的话,你可以先不返回,有的话就返回。后面我慢慢补
20-
pres: ["数组的遍历(正向遍历和反向遍历)"],
21-
description: `
12+
const date = ctx.query.date; // 用户指定的实际
13+
14+
if (date) {
15+
ctx.body = success({
16+
day: 2,
17+
title: "821. 字符的最短距离",
18+
link: "https://leetcode-cn.com/problems/plus-one",
19+
tags: ["基础篇", "数组"], // 目前所有 README 都是没有的。因此如果没有的话,你可以先不返回,有的话就返回。后面我慢慢补
20+
pres: ["数组的遍历(正向遍历和反向遍历)"],
21+
description: `
22+
给定一个字符串 S 和一个字符 C。返回一个代表字符串 S 中每个字符到字符串 S 中的字符 C 的最短距离的数组。
23+
24+
示例 1:
25+
26+
输入: S = "loveleetcode", C = 'e'
27+
输出: [3, 2, 1, 0, 1, 0, 0, 1, 2, 2, 1, 0]
28+
说明:
29+
30+
- 字符串 S 的长度范围为 [1, 10000]。
31+
- C 是一个单字符,且保证是字符串 S 里的字符。
32+
- S 和 C 中的所有字母均为小写字母。
33+
34+
`,
35+
});
36+
} else {
37+
ctx.body = success({
38+
day: 1,
39+
title: "66. 加一",
40+
whys: [
41+
"1. 由于是大家第一次打卡,因此出一个简单题。虽然是简单题,但是如果将加 1 改为加任意的数字,那么就变成了一个非常常见的面试题",
42+
],
43+
link: "https://leetcode-cn.com/problems/plus-one",
44+
tags: ["基础篇", "数组"], // 目前所有 README 都是没有的。因此如果没有的话,你可以先不返回,有的话就返回。后面我慢慢补
45+
pres: ["数组的遍历(正向遍历和反向遍历)"],
46+
description: `
2247
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。
2348
2449
最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。
@@ -36,7 +61,8 @@ router.get("/api/v1/daily-problem", async (ctx) => {
3661
输出: [4,3,2,2]
3762
解释: 输入数组表示数字 4321。
3863
`,
39-
});
64+
});
65+
}
4066
});
4167

4268
router.get("/api/v1/daily-problem/solution", async (ctx) => {

static/solution/generate.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ const fs = require("fs");
22

33
const { encrypt } = require("../../utils/crypto.js");
44

5-
const solutions = {
6-
1: {},
7-
};
5+
const solutions = {};
86

9-
[1].forEach((i) => {
7+
[1, 2].forEach((i) => {
8+
solutions[i] = {};
109
solutions[i].content = encrypt(
1110
Buffer.from(fs.readFileSync(`./d${i}.md`), "utf8")
1211
);

0 commit comments

Comments
 (0)