diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 380f6a59f18be..75f2788abda2e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,6 +1,7 @@ name: deploy on: + workflow_dispatch: push: branches: - main @@ -12,22 +13,14 @@ on: - lcof/** - lcci/** - basic/** - workflow_dispatch: - -env: - MKDOCS_API_KEYS: ${{ secrets.MKDOCS_API_KEYS }} - -permissions: - contents: write concurrency: group: ${{github.workflow}} - ${{github.ref}} cancel-in-progress: true jobs: - deploy: + build: runs-on: ubuntu-latest - if: github.repository == 'doocs/leetcode' steps: - uses: actions/checkout@v4 - uses: actions/checkout@v4 @@ -62,36 +55,36 @@ jobs: python3 -m pip install -r requirements.txt python3 -m pip install "mkdocs-material[imaging]" sudo apt-get install pngquant + + - name: Set MKDOCS_API_KEYS environment variable + run: echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV - run: | python3 main.py mkdocs build -f mkdocs.yml mkdocs build -f mkdocs-en.yml - - name: Deploy - uses: peaceiris/actions-gh-pages@v4 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./site - cname: leetcode.doocs.org + - name: Generate CNAME file + run: echo "leetcode.doocs.org" > ./site/CNAME - # sync: - # runs-on: ubuntu-latest - # needs: deploy - # if: github.repository == 'doocs/leetcode' - # steps: - # - name: Sync to gitee.com - # uses: wearerequired/git-mirror-action@master - # env: - # SSH_PRIVATE_KEY: ${{ secrets.RSA_PRIVATE_KEY }} - # with: - # source-repo: git@github.com:doocs/leetcode.git - # destination-repo: git@gitee.com:Doocs/leetcode.git + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./site - # - name: Build Gitee Pages - # uses: yanglbme/gitee-pages-action@main - # with: - # gitee-username: yanglbme - # gitee-password: ${{ secrets.GITEE_PASSWORD }} - # gitee-repo: doocs/leetcode - # branch: gh-pages + # Deployment job + deploy: + needs: build + permissions: + pages: write + id-token: write + environment: + name: github_pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/solution/1300-1399/1399.Count Largest Group/README.md b/solution/1300-1399/1399.Count Largest Group/README.md index ee880ec654ac2..a851ee797e8ff 100644 --- a/solution/1300-1399/1399.Count Largest Group/README.md +++ b/solution/1300-1399/1399.Count Largest Group/README.md @@ -74,7 +74,7 @@ tags: 最后返回 $ans$ 即可。 -时间复杂度 $O(n \times \log M)$,空间复杂度 $(\log M)$。其中 $n$ 为给定的数字,而 $M$ 是 $n$ 的数字范围。 +时间复杂度 $O(n \times \log n)$,空间复杂度 $(\log n)$。其中 $n$ 为给定的数字。 @@ -177,7 +177,7 @@ func countLargestGroup(n int) (ans int) { ```ts function countLargestGroup(n: number): number { - const cnt: number[] = new Array(40).fill(0); + const cnt: number[] = Array(40).fill(0); let mx = 0; let ans = 0; for (let i = 1; i <= n; ++i) { @@ -197,6 +197,36 @@ function countLargestGroup(n: number): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn count_largest_group(n: i32) -> i32 { + let mut cnt = vec![0; 40]; + let mut ans = 0; + let mut mx = 0; + + for i in 1..=n { + let mut s = 0; + let mut x = i; + while x > 0 { + s += x % 10; + x /= 10; + } + cnt[s as usize] += 1; + if mx < cnt[s as usize] { + mx = cnt[s as usize]; + ans = 1; + } else if mx == cnt[s as usize] { + ans += 1; + } + } + + ans + } +} +``` + diff --git a/solution/1300-1399/1399.Count Largest Group/README_EN.md b/solution/1300-1399/1399.Count Largest Group/README_EN.md index 4b9c648f3b6a5..c30865d5c0206 100644 --- a/solution/1300-1399/1399.Count Largest Group/README_EN.md +++ b/solution/1300-1399/1399.Count Largest Group/README_EN.md @@ -65,7 +65,7 @@ We enumerate each number in $[1,..n]$, calculate its sum of digits $s$, then inc Finally, we return $ans$. -The time complexity is $O(n \times \log M)$, and the space complexity is $O(\log M)$. Where $n$ is the given number, and $M$ is the range of $n$. +The time complexity is $O(n \times \log n)$, and the space complexity is $O(\log n)$, where $n$ is the given number. @@ -168,7 +168,7 @@ func countLargestGroup(n int) (ans int) { ```ts function countLargestGroup(n: number): number { - const cnt: number[] = new Array(40).fill(0); + const cnt: number[] = Array(40).fill(0); let mx = 0; let ans = 0; for (let i = 1; i <= n; ++i) { @@ -188,6 +188,36 @@ function countLargestGroup(n: number): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn count_largest_group(n: i32) -> i32 { + let mut cnt = vec![0; 40]; + let mut ans = 0; + let mut mx = 0; + + for i in 1..=n { + let mut s = 0; + let mut x = i; + while x > 0 { + s += x % 10; + x /= 10; + } + cnt[s as usize] += 1; + if mx < cnt[s as usize] { + mx = cnt[s as usize]; + ans = 1; + } else if mx == cnt[s as usize] { + ans += 1; + } + } + + ans + } +} +``` + diff --git a/solution/1300-1399/1399.Count Largest Group/Solution.rs b/solution/1300-1399/1399.Count Largest Group/Solution.rs new file mode 100644 index 0000000000000..9dd751501581a --- /dev/null +++ b/solution/1300-1399/1399.Count Largest Group/Solution.rs @@ -0,0 +1,25 @@ +impl Solution { + pub fn count_largest_group(n: i32) -> i32 { + let mut cnt = vec![0; 40]; + let mut ans = 0; + let mut mx = 0; + + for i in 1..=n { + let mut s = 0; + let mut x = i; + while x > 0 { + s += x % 10; + x /= 10; + } + cnt[s as usize] += 1; + if mx < cnt[s as usize] { + mx = cnt[s as usize]; + ans = 1; + } else if mx == cnt[s as usize] { + ans += 1; + } + } + + ans + } +} diff --git a/solution/1300-1399/1399.Count Largest Group/Solution.ts b/solution/1300-1399/1399.Count Largest Group/Solution.ts index 44c9b6f05b7a2..c2c3401bf6970 100644 --- a/solution/1300-1399/1399.Count Largest Group/Solution.ts +++ b/solution/1300-1399/1399.Count Largest Group/Solution.ts @@ -1,5 +1,5 @@ function countLargestGroup(n: number): number { - const cnt: number[] = new Array(40).fill(0); + const cnt: number[] = Array(40).fill(0); let mx = 0; let ans = 0; for (let i = 1; i <= n; ++i) {