From cc45842d324b2fd6f1c9204deb61f6eb1225b4e6 Mon Sep 17 00:00:00 2001 From: tianzuzhao Date: Mon, 30 Jun 2025 17:53:00 +0800 Subject: [PATCH 1/3] workflows --- .github/workflows/code-quality.yml | 96 ++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/code-quality.yml diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 0000000..2b839cf --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,96 @@ +name: 代码质量检查 + +# 触发条件:推送到任何分支,或者创建Pull Request +on: + push: + branches: ['**'] + pull_request: + branches: ['master', 'main'] + +jobs: + code-quality: + name: 代码质量检查 + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x, 20.x] + + steps: + # 检出代码 + - name: 检出代码 + uses: actions/checkout@v4 + + # 设置Node.js环境 + - name: 设置 Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + + # 安装依赖 + - name: 安装依赖 + run: yarn install --frozen-lockfile + + # 运行ESLint检查 + - name: 运行 ESLint 检查 + run: yarn lint + + # 运行Prettier格式检查 + - name: 运行 Prettier 格式检查 + run: yarn format:check + + # 运行TypeScript类型检查 + - name: 运行 TypeScript 类型检查 + run: npx tsc --noEmit + + # 如果是Pull Request,添加评论显示检查结果 + - name: 添加 PR 评论 + if: failure() && github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '❌ 代码质量检查失败!请运行 `yarn lint:fix` 和 `yarn format` 来修复问题。' + }) + + # 自动修复作业(仅在推送到非主分支时运行) + auto-fix: + name: 自动修复格式问题 + runs-on: ubuntu-latest + if: github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main' && github.event_name == 'push' + + steps: + - name: 检出代码 + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: 设置 Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + cache: 'yarn' + + - name: 安装依赖 + run: yarn install --frozen-lockfile + + - name: 运行自动修复 + run: | + yarn lint:fix + yarn format + + - name: 提交修复 + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add . + if git diff --staged --quiet; then + echo "没有需要修复的格式问题" + else + git commit -m "🎨 自动修复代码格式 [skip ci]" + git push + fi From 2ec7038ad48966d0ca80a6cb9f27350d66d2e9f7 Mon Sep 17 00:00:00 2001 From: tianzuzhao Date: Wed, 2 Jul 2025 10:24:27 +0800 Subject: [PATCH 2/3] add question2682 --- .../index.md" | 71 +++++++++++++++++++ .../index.ts" | 19 +++++ 2 files changed, 90 insertions(+) create mode 100644 "\347\256\200\345\215\225/280(2682)\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/index.md" create mode 100644 "\347\256\200\345\215\225/280(2682)\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/index.ts" diff --git "a/\347\256\200\345\215\225/280(2682)\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/index.md" "b/\347\256\200\345\215\225/280(2682)\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/index.md" new file mode 100644 index 0000000..d1a0d1c --- /dev/null +++ "b/\347\256\200\345\215\225/280(2682)\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/index.md" @@ -0,0 +1,71 @@ +# 找出转圈游戏输家 + +> 英文标题:Find the Losers of the Circular Game +> +> 难度:Easy +> +> 标签:数组, 哈希表, 模拟 +> + +## 题目描述 + +n 个朋友在玩游戏。这些朋友坐成一个圈,按 顺时针方向 从 1 到 n 编号。准确的说,从第 i 个朋友的位置开始顺时针移动 1 步会到达第 (i + 1) 个朋友的位置(1 <= i < n),而从第 n 个朋友的位置开始顺时针移动 1 步会回到第 1 个朋友的位置。 + +游戏规则如下: + +第 1 个朋友接球。 + + + 接着,第 1 个朋友将球传给距离他顺时针方向 k 步的朋友。 + 然后,接球的朋友应该把球传给距离他顺时针方向 2 * k 步的朋友。 + 接着,接球的朋友应该把球传给距离他顺时针方向 3 * k 步的朋友,以此类推。 + + +换句话说,在第 i 轮中持有球的那位朋友需要将球传递给距离他顺时针方向 i * k 步的朋友。 + +当某个朋友第 2 次接到球时,游戏结束。 + +在整场游戏中没有接到过球的朋友是 输家 。 + +给你参与游戏的朋友数量 n 和一个整数 k ,请按升序排列返回包含所有输家编号的数组 answer 作为答案。 + + + +示例 1: + + +输入:n = 5, k = 2 +输出:[4,5] +解释:以下为游戏进行情况: +1)第 1 个朋友接球,第 1 个朋友将球传给距离他顺时针方向 2 步的玩家 —— 第 3 个朋友。 +2)第 3 个朋友将球传给距离他顺时针方向 4 步的玩家 —— 第 2 个朋友。 +3)第 2 个朋友将球传给距离他顺时针方向 6 步的玩家 —— 第 3 个朋友。 +4)第 3 个朋友接到两次球,游戏结束。 + + +示例 2: + + +输入:n = 4, k = 4 +输出:[2,3,4] +解释:以下为游戏进行情况: +1)第 1 个朋友接球,第 1 个朋友将球传给距离他顺时针方向 4 步的玩家 —— 第 1 个朋友。 +2)第 1 个朋友接到两次球,游戏结束。 + + + +提示: + + + 1 <= k <= n <= 50 + +## 示例测试用例 + +``` +5 +2 +4 +4 +``` + + diff --git "a/\347\256\200\345\215\225/280(2682)\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/index.ts" "b/\347\256\200\345\215\225/280(2682)\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/index.ts" new file mode 100644 index 0000000..528c8a5 --- /dev/null +++ "b/\347\256\200\345\215\225/280(2682)\346\211\276\345\207\272\350\275\254\345\234\210\346\270\270\346\210\217\350\276\223\345\256\266/index.ts" @@ -0,0 +1,19 @@ +/** + * 找出转圈游戏输家 + * 难度:Easy + * 标签:数组, 哈希表, 模拟 + */ + +// 在这里实现你的解决方案 +function circularGameLosers(n: number, k: number): number[] { + const set = new Set(new Array(n).fill(0).map((_, idx) => idx + 1)); + + let cur = 1; + for (let i = 1; set.has(cur); i++) { + set.delete(cur); + cur = (cur + k * i) % n; + cur = cur === 0 ? n : cur; + } + + return Array.from(set.values()); +} From d68f4bc1f07332c2fc7e27f453130eba71ae40f3 Mon Sep 17 00:00:00 2001 From: tianzuzhao Date: Wed, 2 Jul 2025 10:27:40 +0800 Subject: [PATCH 3/3] remove ci --- .github/workflows/code-quality.yml | 96 ------------------------------ 1 file changed, 96 deletions(-) delete mode 100644 .github/workflows/code-quality.yml diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml deleted file mode 100644 index 2b839cf..0000000 --- a/.github/workflows/code-quality.yml +++ /dev/null @@ -1,96 +0,0 @@ -name: 代码质量检查 - -# 触发条件:推送到任何分支,或者创建Pull Request -on: - push: - branches: ['**'] - pull_request: - branches: ['master', 'main'] - -jobs: - code-quality: - name: 代码质量检查 - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.x, 20.x] - - steps: - # 检出代码 - - name: 检出代码 - uses: actions/checkout@v4 - - # 设置Node.js环境 - - name: 设置 Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - cache: 'yarn' - - # 安装依赖 - - name: 安装依赖 - run: yarn install --frozen-lockfile - - # 运行ESLint检查 - - name: 运行 ESLint 检查 - run: yarn lint - - # 运行Prettier格式检查 - - name: 运行 Prettier 格式检查 - run: yarn format:check - - # 运行TypeScript类型检查 - - name: 运行 TypeScript 类型检查 - run: npx tsc --noEmit - - # 如果是Pull Request,添加评论显示检查结果 - - name: 添加 PR 评论 - if: failure() && github.event_name == 'pull_request' - uses: actions/github-script@v7 - with: - script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: '❌ 代码质量检查失败!请运行 `yarn lint:fix` 和 `yarn format` 来修复问题。' - }) - - # 自动修复作业(仅在推送到非主分支时运行) - auto-fix: - name: 自动修复格式问题 - runs-on: ubuntu-latest - if: github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main' && github.event_name == 'push' - - steps: - - name: 检出代码 - uses: actions/checkout@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - - name: 设置 Node.js - uses: actions/setup-node@v4 - with: - node-version: '20.x' - cache: 'yarn' - - - name: 安装依赖 - run: yarn install --frozen-lockfile - - - name: 运行自动修复 - run: | - yarn lint:fix - yarn format - - - name: 提交修复 - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add . - if git diff --staged --quiet; then - echo "没有需要修复的格式问题" - else - git commit -m "🎨 自动修复代码格式 [skip ci]" - git push - fi