diff --git a/.github/workflows/generator.yml b/.github/workflows/generator.yml new file mode 100644 index 0000000..aee7c8f --- /dev/null +++ b/.github/workflows/generator.yml @@ -0,0 +1,25 @@ +name: generator + +on: + push: + branches: [ master ] + + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, 'ci skip')" + + steps: + - uses: actions/checkout@v4.1.0 + - name: Update readme + uses: linuxsuren/yaml-readme@v0.0.16 + env: + GH_TOKEN: ${{ secrets.GH_SECRETS }} + with: + pattern: 'items/*.yaml' + username: linuxsuren + org: devops-ws + repo: learn-code + sortby: '!rank' diff --git a/README.tpl b/README.tpl new file mode 100644 index 0000000..371f421 --- /dev/null +++ b/README.tpl @@ -0,0 +1,8 @@ +# learn-code +Improve your code skills via LeetCode + +| 题目 | 难度 | +|---|---|---| +{{- range $val := .}} +| [{{$val.description}}]({{$val.link}}) | {{$val.rank}} | +{{- end}} diff --git a/items/palindrome.md b/items/palindrome.md new file mode 100644 index 0000000..6c8f28b --- /dev/null +++ b/items/palindrome.md @@ -0,0 +1,33 @@ +--- +description: 回文数 +rank: 1 +link: https://leetcode.cn/problems/palindrome-number/ +--- + +```golang +func isPalindrome(num int) bool { + if num < 0 { + return false + } + if num == 0 { + return true + } + nums := make([]int, 0) + var token int + var count int + + for num != 0 { + token = num % 10 + nums = append(nums, token) + count++ + num /= 10 + } + + for i := 0; i < count / 2; i++ { + if nums[i] != nums[count-i-1] { + return false + } + } + return true +} +```