{"id":20367776,"url":"https://github.com/ybfacc/lc-tool","last_synced_at":"2026-05-14T12:32:14.263Z","repository":{"id":143885371,"uuid":"314004670","full_name":"YBFACC/lc-tool","owner":"YBFACC","description":"js、ts的常用数据结构。方便写leetcode调用","archived":false,"fork":false,"pushed_at":"2021-08-13T08:16:04.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-30T20:55:37.467Z","etag":null,"topics":["javascript","leetcode","typescript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YBFACC.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-18T17:15:07.000Z","updated_at":"2021-08-13T08:16:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"118202ab-5126-4598-b99c-0c8ff47f2ddc","html_url":"https://github.com/YBFACC/lc-tool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/YBFACC/lc-tool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YBFACC%2Flc-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YBFACC%2Flc-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YBFACC%2Flc-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YBFACC%2Flc-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YBFACC","download_url":"https://codeload.github.com/YBFACC/lc-tool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YBFACC%2Flc-tool/sbom","scorecard":{"id":153902,"data":{"date":"2025-08-11","repo":{"name":"github.com/YBFACC/lc-tool","commit":"1d459b982ac348358ece2e12428e4a1075c31986"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/21 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T11:17:28.280Z","repository_id":143885371,"created_at":"2025-08-16T11:17:28.280Z","updated_at":"2025-08-16T11:17:28.280Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006750,"owners_count":26084182,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","leetcode","typescript"],"created_at":"2024-11-15T00:34:42.335Z","updated_at":"2025-10-11T09:41:52.032Z","avatar_url":"https://github.com/YBFACC.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 刷题数据结构工具\n\n![NPM](https://img.shields.io/npm/l/lc-tool?color=blue\u0026style=flat-square)\t![npm](https://img.shields.io/npm/v/lc-tool?logo=npm\u0026style=flat-square)\t![npm bundle size](https://img.shields.io/bundlephobia/min/lc-tool?logo=npm\u0026style=flat-square)\n\n方便js，ts写代码，调用时直接有提示补进。\n\n⚠️*ps：ListNode，TreeNode，RunScript均参考[leetcode-class](https://github.com/LoveofRedMoon/LeetCode-Class)这个库。将代码精简并改成typescript。*\n\n如果有错误，欢迎开[issues](https://github.com/YBFACC/lc-tool/issues)。\n\n## 使用方法\n\nts：\n\n```typescript\nimport { AVLTree, Heap, TreeNode, ListNode, RunScript, Node, SegmentTree, Trie } from 'lc-tool';\n\nfunction topKFrequent(nums: number[], k: number): number[] {\n  const heap = new Heap()\n  //....\n};\n\ntopKFrequent(\n  //...\n)\n```\n\njs：\n\n```javascript\nconst { AVLTree, Heap, TreeNode, ListNode, RunScript, Node, SegmentTree, Trie } = require('lc-tool')\n\n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number[]}\n */\nvar topKFrequent = function (nums, k) {\n\tconst heap = new Heap()\n\t//.....\n}\n\ntopKFrequent(\n  //...\n)\n\n\n```\n\n可以配合vscode的用户片段，快速导入文件中。\n\n## TreeNode\n### constructor(*val*?: *number*, *left*?: TreeNode | *null*, *right*?: TreeNode | *null*) \n\n 构造函数\n\n  ```typescript\nconst root =new TreeNode(1)\n  ```\n### TreeNode.create(*arr*: *number*[])\n  根据给的Array创建树\n  ```typescript\nconst tree = TreeNode.create([1, 2, 3, 4, 5])\n  ```\n\n\n\n## ListNode\n\n### constructor(*val*?: *number*, *next*?: ListNode | *null*)\n\n构造函数\n\n```typescript\nconst listnode = new ListNode()\n```\n\n### ListNode.create(*arr*: *number*[])\n\n 根据给的Array创建树\n\n```typescript\nconst list = ListNode.create([-1, 5, 3, 4, 0]\n```\n\n\n\n## RunScript\n\n### RunScript(*commonds*: *string*[], *inputs*: *any*[], *classes*: *any*): *any*[]\n\n运行设计类题目。\n\n*commonds*和*inputs*是题目输入的2项\n\n*classes*是需要创建对象的类\n\n```typescript\nimport { RunScript } from \"lc-tool\";\n\nclass LFUCache {\n  //..... \n}\n\n/**\n * Your LFUCache object will be instantiated and called as such:\n * var obj = new LFUCache(capacity)\n * var param_1 = obj.get(key)\n * obj.put(key,value)\n */\n\n// [\"LFUCache\", \"put\", \"get\", \"put\", \"get\", \"get\"]\n// [[1], [2, 1], [2], [3, 2], [2], [3]]\n\nRunScript([\"LFUCache\", \"put\", \"get\", \"put\", \"get\", \"get\"]\n  , [[1], [2, 1], [2], [3, 2], [2], [3]], LFUCache)\n\n```\n\n\n\n## Heap\n\n  堆（优先队列）\n\n1. 默认为**小顶堆**。可以在初始化就插入数组，也可以后面手动使用insert插入\n\n```typescript\nconst heap1 = new Heap()\nconst heap2 = new Heap([1,2,3])\n```\n\n2. 自定义排序\n\n   \\\u003e=:降序（小顶堆）\n\n   \\\u003c=:升序（大顶堆）\n\n```typescript\nconst heap3 = new Heap([], (a, b) =\u003e {\n  return a \u003e= b\n})\n```\n\n3. 复杂数据结构\n\n```typescript\nconst heap3 = new Heap([], (a, b) =\u003e {\n  if (a[1] === b[1]) {\n    return a[0] \u003c= b[0]\n  }\n  return a[1] \u003c= b[1]\n})\n\n```\n\n### offer(data: T):*boolean*\n\n  插入\n\n```typescript\nheap3.offer(3)\n```\n\n### clear(): *void*\n\n清空堆\n\n### poll(): T | null\n\n  弹出堆首\n\n```typescript\nheap3.poll()\n```\n\n### remove(*val*: *T*): *boolean*\n\n删除堆中的特定元素（注意删除的时间复杂度是O(n)）\n\n```typescript\nheap3.remove(3)\n```\n\n### isEmpty(): *boolean*\n\n堆中是否有元素\n\n```typescript\nheap3.isEmpty()\n```\n\n### peek(): *T* | *null*\n\n得到堆顶的值\n\n```typescript\nheap3.peek()\n```\n\n### get size(): *number*\n\n得到堆中的元素个数\n\n```typescript\nheap3.size\n```\n\n\n\n## AVLTree\n  平衡二叉搜索树\n\n```typescript\nclass AVLTreeNode {\n  val: number\n  height: number\n  left: AVLTreeNode | null\n  right: AVLTreeNode | null\n  left_count = 0 //左子树次数的统计\n  rihgt_count = 0 //右子树次数的统计\n  count = 1 // 当前节点出现的次数\n  constructor(val: number) {\n    this.val = val\n    this.left = this.right = null\n    this.height = 1\n  }\n}\n```\n\n```typescript\nconst avl = new AVLTree()\n```\n\n### insert(*val*: *number*):*void*\n  插入val\n\n```typescript\navl.insert(2)\navl.insert(3)\navl.insert(1)\n```\n\n### getPre(*val*: *number*): AVLTreeNode | *null*\n  得到小于x的最大值\n\n```typescript\navl.getNext(2)\n```\n\n### getNext(*val*: *number*): AVLTreeNode | *null*\n  得到大于x的最小值\n\n```typescript\navl.getPre(2)\n```\n\n### remove(*val*: *number*):*boolean*\n  移除x\n\n```typescript\navl.remove(2)\n```\n\n### search(*val*: *number*): AVLTreeNode | *null*\n\n查找是否已经有val\n\n```typescript\navl.search(2)\n```\n\n### min(): AVLTreeNode | *null*\n\n  得到当前最小值\n\n```typescript\navl.min()\n```\n\n### max(): AVLTreeNode | *null*\n  得到当前最大值\n\n```typescript\navl.max()\n```\n\n### length\n\n得到树中的元素个数\n\n```typescript\navl.length\n```\n\n### search_count(*val*: *number*): *number*\n\n统计小于val的节点出现次数。\n\n删除节点后，正确性未验证。\n\n\n\n## SegmentTree\n\n树状数组，单点更新，区间查询。\n\n使用注意：树状数组下标从1开始。\n\n### constructor(*list*: *number*[] | *number*)\n\n```typescript\nconst a = [2, 3, 1, 5, 8, 2, 5, 9]\n\nconst st1 = new SegmentTree(a)\nconst st2 = new SegmentTree(a.length)\n```\n\n### update(*index*: *number*, *val*: *number*): *void*\n\n更新某个下标的值\n\n### query(*i*: *number*): *number*\n\n得到下标1-i的区间和\n\n```typescript\nconsole.log(st1.query(3))\n\nconsole.log(st1.update(1, 100))\n\nconsole.log(st1.query(3))\n```\n\n\n\n## 链式前向星存图\n\n一种保存图的方法，适合边少的图\n\n### constructor(*n*: *number*) \n\n初始化存边的数量\n\n### add(*a*: *number*, *b*: *number*, *c*: *number*)\n\n添加边。\n\n### search(*target*: *number*): *number*[][]\n\n查找以target从出发的边。以倒叙输出。\n\n\n\n## NumberOfTrailingZeros\n\n计算一个10进制数在2进制下，从最后一个1到末尾的0的个数\n\n\n\n## Node\n\n例题[1650. 二叉树的最近公共祖先 III](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree-iii/)\n[1484. 克隆含随机指针的二叉树](https://leetcode-cn.com/problems/clone-binary-tree-with-random-pointer/)\n\n\n## 文件目录\n\n```\n├─.gitignore\n├─LICENSE\n├─index.d.ts\n├─index.js            入口文件\n├─package-lock.json\n├─package.json\n├─readme.md\n├─tsconfig.json       ts编译配置\n├─ts                  ts源码\n| ├─index.ts\n| ├─src\n| |  ...\n├─src                 编译完成的代码\n|  ....\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fybfacc%2Flc-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fybfacc%2Flc-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fybfacc%2Flc-tool/lists"}