From 099126738a64536bd5b07c56813e62f95b800327 Mon Sep 17 00:00:00 2001 From: ccagml Date: Sat, 28 Jan 2023 09:53:49 +0800 Subject: [PATCH 01/11] =?UTF-8?q?hideScore=20=E9=85=8D=E7=BD=AE=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E5=88=B7=E6=96=B0=E9=A2=98=E7=9B=AE=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++-- package-lock.json | 4 ++-- package.json | 2 +- src/controller/TreeViewController.ts | 22 ++++++++++++++++++---- src/service/TreeDataService.ts | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ddb715..8d25b7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## version 2.12.3 + +- hideScore 配置变化时刷新题目列表 + ## version 2.12.2 - 修复 使用${tag}作为文件夹名称不生效 @@ -5,8 +9,8 @@ ## version 2.12.1 -- 配置filePath文件名 增加 ${yyyymmdd}格式 -- 配置filePath文件名 增加 ${timestamp}格式 +- 配置 filePath 文件名 增加 ${yyyymmdd}格式 +- 配置 filePath 文件名 增加 ${timestamp}格式 ## version 2.11.16 diff --git a/package-lock.json b/package-lock.json index bba72f1..7455b8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-leetcode-problem-rating", - "version": "2.12.1", + "version": "2.12.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-leetcode-problem-rating", - "version": "2.12.1", + "version": "2.12.2", "license": "MIT", "dependencies": { "ansi-styles": "3.2.1", diff --git a/package.json b/package.json index 868f2a4..9091fa8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-leetcode-problem-rating", "displayName": "LeetCode", "description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了", - "version": "2.12.2", + "version": "2.12.3", "author": "ccagml", "publisher": "ccagml", "license": "MIT", diff --git a/src/controller/TreeViewController.ts b/src/controller/TreeViewController.ts index 17e3c19..b2a6f8f 100644 --- a/src/controller/TreeViewController.ts +++ b/src/controller/TreeViewController.ts @@ -11,7 +11,7 @@ import * as lodash from "lodash"; import * as path from "path"; import * as vscode from "vscode"; import { toNumber } from "lodash"; -import { Disposable, Uri, window } from "vscode"; +import { Disposable, Uri, window, workspace, ConfigurationChangeEvent } from "vscode"; import { SearchNode, userContestRankingObj, @@ -78,7 +78,16 @@ class TreeViewController implements Disposable { private searchSet: Map = new Map(); private waitTodayQuestion: boolean; private waitUserContest: boolean; + private configurationChangeListener: Disposable; + constructor() { + this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => { + if (event.affectsConfiguration("leetcode-problem-rating.hideScore")) { + treeDataService.refresh(); + bricksDataService.refresh(); + } + }, this); + } // 获取当前文件的路径 /** * It returns the path of the currently active file, or undefined if there is no active file @@ -996,7 +1005,7 @@ class TreeViewController implements Disposable { } public async resolveTagForProblem(problem: IProblem): Promise { - let path_en_tags = treeDataService.getTagsDataEn(problem.id) + let path_en_tags = treeDataService.getTagsDataEn(problem.id); if (path_en_tags.length === 1) { return path_en_tags[0]; } @@ -1078,7 +1087,7 @@ class TreeViewController implements Disposable { const temp_searchSet: Map = this.searchSet; const temp_waitTodayQuestion: boolean = this.waitTodayQuestion; const temp_waitUserContest: boolean = this.waitUserContest; - this.dispose(); + this.clearCache(); let user_score = statusBarService.getUserContestScore(); for (const problem of await this.getAllProblems()) { this.explorerNodeMap.set(problem.id, new NodeModel(problem, true, user_score)); @@ -1492,7 +1501,7 @@ class TreeViewController implements Disposable { return this.applySortingStrategy(res); } - public dispose(): void { + public clearCache(): void { this.explorerNodeMap.clear(); this.companySet.clear(); this.tagSet.clear(); @@ -1500,6 +1509,11 @@ class TreeViewController implements Disposable { this.qidToFid.clear(); } + public dispose(): void { + this.configurationChangeListener.dispose(); + this.clearCache(); + } + private sortSubCategoryNodes(subCategoryNodes: NodeModel[], category: Category): void { switch (category) { case Category.Difficulty: diff --git a/src/service/TreeDataService.ts b/src/service/TreeDataService.ts index 04012ae..718c6b7 100644 --- a/src/service/TreeDataService.ts +++ b/src/service/TreeDataService.ts @@ -122,7 +122,7 @@ export class TreeDataService implements vscode.TreeDataProvider { return []; } else { switch ( - element.id // First-level + element.id // First-level ) { case Category.All: return treeViewController.getAllNodes(); From e0f5ac8740990c467114633df1923d3e0e7650f4 Mon Sep 17 00:00:00 2001 From: ccagml Date: Sat, 28 Jan 2023 17:07:31 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E9=A2=98=E8=A7=A3=E6=98=BE=E7=A4=BA=20ka?= =?UTF-8?q?tex=20=E6=95=B0=E5=AD=A6=E5=85=AC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ package.json | 2 +- resources/katexcss/github-markdown.min.css | 2 ++ resources/katexcss/kates.min.css | 1 + src/service/MarkdownService.ts | 7 ++++++- src/service/SolutionService.ts | 20 +++++++++++++++++++- 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 resources/katexcss/github-markdown.min.css create mode 100755 resources/katexcss/kates.min.css diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d25b7b..d4d97bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## version 2.13.1 + +- 题解显示 katex 数学公式 + ## version 2.12.3 - hideScore 配置变化时刷新题目列表 diff --git a/package.json b/package.json index 9091fa8..a540a1b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-leetcode-problem-rating", "displayName": "LeetCode", "description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了", - "version": "2.12.3", + "version": "2.13.1", "author": "ccagml", "publisher": "ccagml", "license": "MIT", diff --git a/resources/katexcss/github-markdown.min.css b/resources/katexcss/github-markdown.min.css new file mode 100755 index 0000000..1ff64f7 --- /dev/null +++ b/resources/katexcss/github-markdown.min.css @@ -0,0 +1,2 @@ +.markdown-body .octicon{display:inline-block;fill:currentColor;vertical-align:text-bottom}.markdown-body .anchor{float:left;line-height:1;margin-left:-20px;padding-right:4px}.markdown-body .anchor:focus{outline:0}.markdown-body h1 .octicon-link,.markdown-body h2 .octicon-link,.markdown-body h3 .octicon-link,.markdown-body h4 .octicon-link,.markdown-body h5 .octicon-link,.markdown-body h6 .octicon-link{color:#1b1f23;vertical-align:middle;visibility:hidden}.markdown-body h1:hover .anchor,.markdown-body h2:hover .anchor,.markdown-body h3:hover .anchor,.markdown-body h4:hover .anchor,.markdown-body h5:hover .anchor,.markdown-body h6:hover .anchor{text-decoration:none}.markdown-body h1:hover .anchor .octicon-link,.markdown-body h2:hover .anchor .octicon-link,.markdown-body h3:hover .anchor .octicon-link,.markdown-body h4:hover .anchor .octicon-link,.markdown-body h5:hover .anchor .octicon-link,.markdown-body h6:hover .anchor .octicon-link{visibility:visible}.markdown-body h1:hover .anchor .octicon-link:before,.markdown-body h2:hover .anchor .octicon-link:before,.markdown-body h3:hover .anchor .octicon-link:before,.markdown-body h4:hover .anchor .octicon-link:before,.markdown-body h5:hover .anchor .octicon-link:before,.markdown-body h6:hover .anchor .octicon-link:before{width:16px;height:16px;content:' ';display:inline-block;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' version='1.1' width='16' height='16' aria-hidden='true'%3E%3Cpath fill-rule='evenodd' d='M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z'%3E%3C/path%3E%3C/svg%3E")}.markdown-body{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;line-height:1.5;color:#24292e;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;font-size:16px;line-height:1.5;word-wrap:break-word}.markdown-body details{display:block}.markdown-body summary{display:list-item}.markdown-body a{background-color:initial}.markdown-body a:active,.markdown-body a:hover{outline-width:0}.markdown-body strong{font-weight:inherit;font-weight:bolder}.markdown-body h1{font-size:2em;margin:.67em 0}.markdown-body img{border-style:none}.markdown-body code,.markdown-body kbd,.markdown-body pre{font-family:monospace,monospace;font-size:1em}.markdown-body hr{box-sizing:initial;height:0;overflow:visible}.markdown-body input{font:inherit;margin:0}.markdown-body input{overflow:visible}.markdown-body [type=checkbox]{box-sizing:border-box;padding:0}.markdown-body *{box-sizing:border-box}.markdown-body input{font-family:inherit;font-size:inherit;line-height:inherit}.markdown-body a{color:#0366d6;text-decoration:none}.markdown-body a:hover{text-decoration:underline}.markdown-body strong{font-weight:600}.markdown-body hr{height:0;margin:15px 0;overflow:hidden;background:0 0;border:0;border-bottom:1px solid #dfe2e5}.markdown-body hr:after,.markdown-body hr:before{display:table;content:""}.markdown-body hr:after{clear:both}.markdown-body table{border-spacing:0;border-collapse:collapse}.markdown-body td,.markdown-body th{padding:0}.markdown-body details summary{cursor:pointer}.markdown-body kbd{display:inline-block;padding:3px 5px;font:11px SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;line-height:10px;color:#444d56;vertical-align:middle;background-color:#fafbfc;border:1px solid #d1d5da;border-radius:3px;box-shadow:inset 0 -1px 0 #d1d5da}.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6{margin-top:0;margin-bottom:0}.markdown-body h1{font-size:32px}.markdown-body h1,.markdown-body h2{font-weight:600}.markdown-body h2{font-size:24px}.markdown-body h3{font-size:20px}.markdown-body h3,.markdown-body h4{font-weight:600}.markdown-body h4{font-size:16px}.markdown-body h5{font-size:14px}.markdown-body h5,.markdown-body h6{font-weight:600}.markdown-body h6{font-size:12px}.markdown-body p{margin-top:0;margin-bottom:10px}.markdown-body blockquote{margin:0}.markdown-body ol,.markdown-body ul{padding-left:0;margin-top:0;margin-bottom:0}.markdown-body ol ol,.markdown-body ul ol{list-style-type:lower-roman}.markdown-body ol ol ol,.markdown-body ol ul ol,.markdown-body ul ol ol,.markdown-body ul ul ol{list-style-type:lower-alpha}.markdown-body dd{margin-left:0}.markdown-body code,.markdown-body pre{font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:12px}.markdown-body pre{margin-top:0;margin-bottom:0}.markdown-body input::-webkit-inner-spin-button,.markdown-body input::-webkit-outer-spin-button{margin:0;-webkit-appearance:none;appearance:none}.markdown-body :checked+.radio-label{position:relative;z-index:1;border-color:#0366d6}.markdown-body .border{border:1px solid #e1e4e8!important}.markdown-body .border-0{border:0!important}.markdown-body .border-bottom{border-bottom:1px solid #e1e4e8!important}.markdown-body .rounded-1{border-radius:3px!important}.markdown-body .bg-white{background-color:#fff!important}.markdown-body .bg-gray-light{background-color:#fafbfc!important}.markdown-body .text-gray-light{color:#6a737d!important}.markdown-body .mb-0{margin-bottom:0!important}.markdown-body .my-2{margin-top:8px!important;margin-bottom:8px!important}.markdown-body .pl-0{padding-left:0!important}.markdown-body .py-0{padding-top:0!important;padding-bottom:0!important}.markdown-body .pl-1{padding-left:4px!important}.markdown-body .pl-2{padding-left:8px!important}.markdown-body .py-2{padding-top:8px!important;padding-bottom:8px!important}.markdown-body .pl-3,.markdown-body .px-3{padding-left:16px!important}.markdown-body .px-3{padding-right:16px!important}.markdown-body .pl-4{padding-left:24px!important}.markdown-body .pl-5{padding-left:32px!important}.markdown-body .pl-6{padding-left:40px!important}.markdown-body .f6{font-size:12px!important}.markdown-body .lh-condensed{line-height:1.25!important}.markdown-body .text-bold{font-weight:600!important}.markdown-body .pl-c{color:#6a737d}.markdown-body .pl-c1,.markdown-body .pl-s .pl-v{color:#005cc5}.markdown-body .pl-e,.markdown-body .pl-en{color:#6f42c1}.markdown-body .pl-s .pl-s1,.markdown-body .pl-smi{color:#24292e}.markdown-body .pl-ent{color:#22863a}.markdown-body .pl-k{color:#d73a49}.markdown-body .pl-pds,.markdown-body .pl-s,.markdown-body .pl-s .pl-pse .pl-s1,.markdown-body .pl-sr,.markdown-body .pl-sr .pl-cce,.markdown-body .pl-sr .pl-sra,.markdown-body .pl-sr .pl-sre{color:#032f62}.markdown-body .pl-smw,.markdown-body .pl-v{color:#e36209}.markdown-body .pl-bu{color:#b31d28}.markdown-body .pl-ii{color:#fafbfc;background-color:#b31d28}.markdown-body .pl-c2{color:#fafbfc;background-color:#d73a49}.markdown-body .pl-c2:before{content:"^M"}.markdown-body .pl-sr .pl-cce{font-weight:700;color:#22863a}.markdown-body .pl-ml{color:#735c0f}.markdown-body .pl-mh,.markdown-body .pl-mh .pl-en,.markdown-body .pl-ms{font-weight:700;color:#005cc5}.markdown-body .pl-mi{font-style:italic;color:#24292e}.markdown-body .pl-mb{font-weight:700;color:#24292e}.markdown-body .pl-md{color:#b31d28;background-color:#ffeef0}.markdown-body .pl-mi1{color:#22863a;background-color:#f0fff4}.markdown-body .pl-mc{color:#e36209;background-color:#ffebda}.markdown-body .pl-mi2{color:#f6f8fa;background-color:#005cc5}.markdown-body .pl-mdr{font-weight:700;color:#6f42c1}.markdown-body .pl-ba{color:#586069}.markdown-body .pl-sg{color:#959da5}.markdown-body .pl-corl{text-decoration:underline;color:#032f62}.markdown-body .mb-0{margin-bottom:0!important}.markdown-body .my-2{margin-bottom:8px!important}.markdown-body .my-2{margin-top:8px!important}.markdown-body .pl-0{padding-left:0!important}.markdown-body .py-0{padding-top:0!important;padding-bottom:0!important}.markdown-body .pl-1{padding-left:4px!important}.markdown-body .pl-2{padding-left:8px!important}.markdown-body .py-2{padding-top:8px!important;padding-bottom:8px!important}.markdown-body .pl-3{padding-left:16px!important}.markdown-body .pl-4{padding-left:24px!important}.markdown-body .pl-5{padding-left:32px!important}.markdown-body .pl-6{padding-left:40px!important}.markdown-body .pl-7{padding-left:48px!important}.markdown-body .pl-8{padding-left:64px!important}.markdown-body .pl-9{padding-left:80px!important}.markdown-body .pl-10{padding-left:96px!important}.markdown-body .pl-11{padding-left:112px!important}.markdown-body .pl-12{padding-left:128px!important}.markdown-body hr{border-bottom-color:#eee}.markdown-body kbd{display:inline-block;padding:3px 5px;font:11px SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;line-height:10px;color:#444d56;vertical-align:middle;background-color:#fafbfc;border:1px solid #d1d5da;border-radius:3px;box-shadow:inset 0 -1px 0 #d1d5da}.markdown-body:after,.markdown-body:before{display:table;content:""}.markdown-body:after{clear:both}.markdown-body>:first-child{margin-top:0!important}.markdown-body>:last-child{margin-bottom:0!important}.markdown-body a:not([href]){color:inherit;text-decoration:none}.markdown-body blockquote,.markdown-body details,.markdown-body dl,.markdown-body ol,.markdown-body p,.markdown-body pre,.markdown-body table,.markdown-body ul{margin-top:0;margin-bottom:16px}.markdown-body hr{height:.25em;padding:0;margin:24px 0;background-color:#e1e4e8;border:0}.markdown-body blockquote{padding:0 1em;color:#6a737d;border-left:.25em solid #dfe2e5}.markdown-body blockquote>:first-child{margin-top:0}.markdown-body blockquote>:last-child{margin-bottom:0}.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6{margin-top:24px;margin-bottom:16px;font-weight:600;line-height:1.25}.markdown-body h1{font-size:2em}.markdown-body h1,.markdown-body h2{padding-bottom:.3em;border-bottom:1px solid #eaecef}.markdown-body h2{font-size:1.5em}.markdown-body h3{font-size:1.25em}.markdown-body h4{font-size:1em}.markdown-body h5{font-size:.875em}.markdown-body h6{font-size:.85em;color:#6a737d}.markdown-body ol,.markdown-body ul{padding-left:2em}.markdown-body ol ol,.markdown-body ol ul,.markdown-body ul ol,.markdown-body ul ul{margin-top:0;margin-bottom:0}.markdown-body li{word-wrap:break-all}.markdown-body li>p{margin-top:16px}.markdown-body li+li{margin-top:.25em}.markdown-body dl{padding:0}.markdown-body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:600}.markdown-body dl dd{padding:0 16px;margin-bottom:16px}.markdown-body table{display:block;width:100%;overflow:auto}.markdown-body table th{font-weight:600}.markdown-body table td,.markdown-body table th{padding:6px 13px;border:1px solid #dfe2e5}.markdown-body table tr{background-color:#fff;border-top:1px solid #c6cbd1}.markdown-body table tr:nth-child(2n){background-color:#f6f8fa}.markdown-body img{max-width:100%;box-sizing:initial;background-color:#fff}.markdown-body img[align=right]{padding-left:20px}.markdown-body img[align=left]{padding-right:20px}.markdown-body code{padding:.2em .4em;margin:0;font-size:85%;background-color:rgba(27,31,35,.05);border-radius:3px}.markdown-body pre{word-wrap:normal}.markdown-body pre>code{padding:0;margin:0;font-size:100%;word-break:normal;white-space:pre;background:0 0;border:0}.markdown-body .highlight{margin-bottom:16px}.markdown-body .highlight pre{margin-bottom:0;word-break:normal}.markdown-body .highlight pre,.markdown-body pre{padding:16px;overflow:auto;font-size:85%;line-height:1.45;background-color:#f6f8fa;border-radius:3px}.markdown-body pre code{display:inline;max-width:auto;padding:0;margin:0;overflow:visible;line-height:inherit;word-wrap:normal;background-color:initial;border:0}.markdown-body .commit-tease-sha{display:inline-block;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:90%;color:#444d56}.markdown-body .full-commit .btn-outline:not(:disabled):hover{color:#005cc5;border-color:#005cc5}.markdown-body .blob-wrapper{overflow-x:auto;overflow-y:hidden}.markdown-body .blob-wrapper-embedded{max-height:240px;overflow-y:auto}.markdown-body .blob-num{width:1%;min-width:50px;padding-right:10px;padding-left:10px;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:12px;line-height:20px;color:rgba(27,31,35,.3);text-align:right;white-space:nowrap;vertical-align:top;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-body .blob-num:hover{color:rgba(27,31,35,.6)}.markdown-body .blob-num:before{content:attr(data-line-number)}.markdown-body .blob-code{position:relative;padding-right:10px;padding-left:10px;line-height:20px;vertical-align:top}.markdown-body .blob-code-inner{overflow:visible;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:12px;color:#24292e;word-wrap:normal;white-space:pre}.markdown-body .pl-token.active,.markdown-body .pl-token:hover{cursor:pointer;background:#ffea7f}.markdown-body .tab-size[data-tab-size="1"]{-moz-tab-size:1;tab-size:1}.markdown-body .tab-size[data-tab-size="2"]{-moz-tab-size:2;tab-size:2}.markdown-body .tab-size[data-tab-size="3"]{-moz-tab-size:3;tab-size:3}.markdown-body .tab-size[data-tab-size="4"]{-moz-tab-size:4;tab-size:4}.markdown-body .tab-size[data-tab-size="5"]{-moz-tab-size:5;tab-size:5}.markdown-body .tab-size[data-tab-size="6"]{-moz-tab-size:6;tab-size:6}.markdown-body .tab-size[data-tab-size="7"]{-moz-tab-size:7;tab-size:7}.markdown-body .tab-size[data-tab-size="8"]{-moz-tab-size:8;tab-size:8}.markdown-body .tab-size[data-tab-size="9"]{-moz-tab-size:9;tab-size:9}.markdown-body .tab-size[data-tab-size="10"]{-moz-tab-size:10;tab-size:10}.markdown-body .tab-size[data-tab-size="11"]{-moz-tab-size:11;tab-size:11}.markdown-body .tab-size[data-tab-size="12"]{-moz-tab-size:12;tab-size:12}.markdown-body .task-list-item{list-style-type:none}.markdown-body .task-list-item+.task-list-item{margin-top:3px}.markdown-body .task-list-item input{margin:0 .2em .25em -1.6em;vertical-align:middle} +/*# sourceMappingURL=github-markdown.min.css.map */ diff --git a/resources/katexcss/kates.min.css b/resources/katexcss/kates.min.css new file mode 100755 index 0000000..75b9066 --- /dev/null +++ b/resources/katexcss/kates.min.css @@ -0,0 +1 @@ +@font-face{font-family:KaTeX_AMS;src:url(fonts/KaTeX_AMS-Regular.eot);src:url(fonts/KaTeX_AMS-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_AMS-Regular.woff2) format('woff2'),url(fonts/KaTeX_AMS-Regular.woff) format('woff'),url(fonts/KaTeX_AMS-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Caligraphic;src:url(fonts/KaTeX_Caligraphic-Bold.eot);src:url(fonts/KaTeX_Caligraphic-Bold.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Caligraphic-Bold.woff2) format('woff2'),url(fonts/KaTeX_Caligraphic-Bold.woff) format('woff'),url(fonts/KaTeX_Caligraphic-Bold.ttf) format('ttf');font-weight:700;font-style:normal}@font-face{font-family:KaTeX_Caligraphic;src:url(fonts/KaTeX_Caligraphic-Regular.eot);src:url(fonts/KaTeX_Caligraphic-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Caligraphic-Regular.woff2) format('woff2'),url(fonts/KaTeX_Caligraphic-Regular.woff) format('woff'),url(fonts/KaTeX_Caligraphic-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Fraktur;src:url(fonts/KaTeX_Fraktur-Bold.eot);src:url(fonts/KaTeX_Fraktur-Bold.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Fraktur-Bold.woff2) format('woff2'),url(fonts/KaTeX_Fraktur-Bold.woff) format('woff'),url(fonts/KaTeX_Fraktur-Bold.ttf) format('ttf');font-weight:700;font-style:normal}@font-face{font-family:KaTeX_Fraktur;src:url(fonts/KaTeX_Fraktur-Regular.eot);src:url(fonts/KaTeX_Fraktur-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Fraktur-Regular.woff2) format('woff2'),url(fonts/KaTeX_Fraktur-Regular.woff) format('woff'),url(fonts/KaTeX_Fraktur-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Main;src:url(fonts/KaTeX_Main-Bold.eot);src:url(fonts/KaTeX_Main-Bold.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Main-Bold.woff2) format('woff2'),url(fonts/KaTeX_Main-Bold.woff) format('woff'),url(fonts/KaTeX_Main-Bold.ttf) format('ttf');font-weight:700;font-style:normal}@font-face{font-family:KaTeX_Main;src:url(fonts/KaTeX_Main-Italic.eot);src:url(fonts/KaTeX_Main-Italic.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Main-Italic.woff2) format('woff2'),url(fonts/KaTeX_Main-Italic.woff) format('woff'),url(fonts/KaTeX_Main-Italic.ttf) format('ttf');font-weight:400;font-style:italic}@font-face{font-family:KaTeX_Main;src:url(fonts/KaTeX_Main-Regular.eot);src:url(fonts/KaTeX_Main-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Main-Regular.woff2) format('woff2'),url(fonts/KaTeX_Main-Regular.woff) format('woff'),url(fonts/KaTeX_Main-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Math;src:url(fonts/KaTeX_Math-Italic.eot);src:url(fonts/KaTeX_Math-Italic.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Math-Italic.woff2) format('woff2'),url(fonts/KaTeX_Math-Italic.woff) format('woff'),url(fonts/KaTeX_Math-Italic.ttf) format('ttf');font-weight:400;font-style:italic}@font-face{font-family:KaTeX_SansSerif;src:url(fonts/KaTeX_SansSerif-Regular.eot);src:url(fonts/KaTeX_SansSerif-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_SansSerif-Regular.woff2) format('woff2'),url(fonts/KaTeX_SansSerif-Regular.woff) format('woff'),url(fonts/KaTeX_SansSerif-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Script;src:url(fonts/KaTeX_Script-Regular.eot);src:url(fonts/KaTeX_Script-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Script-Regular.woff2) format('woff2'),url(fonts/KaTeX_Script-Regular.woff) format('woff'),url(fonts/KaTeX_Script-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size1;src:url(fonts/KaTeX_Size1-Regular.eot);src:url(fonts/KaTeX_Size1-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Size1-Regular.woff2) format('woff2'),url(fonts/KaTeX_Size1-Regular.woff) format('woff'),url(fonts/KaTeX_Size1-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size2;src:url(fonts/KaTeX_Size2-Regular.eot);src:url(fonts/KaTeX_Size2-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Size2-Regular.woff2) format('woff2'),url(fonts/KaTeX_Size2-Regular.woff) format('woff'),url(fonts/KaTeX_Size2-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size3;src:url(fonts/KaTeX_Size3-Regular.eot);src:url(fonts/KaTeX_Size3-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Size3-Regular.woff2) format('woff2'),url(fonts/KaTeX_Size3-Regular.woff) format('woff'),url(fonts/KaTeX_Size3-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size4;src:url(fonts/KaTeX_Size4-Regular.eot);src:url(fonts/KaTeX_Size4-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Size4-Regular.woff2) format('woff2'),url(fonts/KaTeX_Size4-Regular.woff) format('woff'),url(fonts/KaTeX_Size4-Regular.ttf) format('ttf');font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Typewriter;src:url(fonts/KaTeX_Typewriter-Regular.eot);src:url(fonts/KaTeX_Typewriter-Regular.eot#iefix) format('embedded-opentype'),url(fonts/KaTeX_Typewriter-Regular.woff2) format('woff2'),url(fonts/KaTeX_Typewriter-Regular.woff) format('woff'),url(fonts/KaTeX_Typewriter-Regular.ttf) format('ttf');font-weight:400;font-style:normal}.katex-display{display:block;margin:1em 0;text-align:center}.katex-display>.katex{display:inline-block}.katex{font:400 1.21em KaTeX_Main;line-height:1.2;white-space:nowrap;text-indent:0}.katex .katex-html{display:inline-block}.katex .katex-mathml{position:absolute;clip:rect(1px,1px,1px,1px);padding:0;border:0;height:1px;width:1px;overflow:hidden}.katex .base,.katex .strut{display:inline-block}.katex .mathit{font-family:KaTeX_Math;font-style:italic}.katex .mathbf{font-family:KaTeX_Main;font-weight:700}.katex .amsrm,.katex .mathbb{font-family:KaTeX_AMS}.katex .mathcal{font-family:KaTeX_Caligraphic}.katex .mathfrak{font-family:KaTeX_Fraktur}.katex .mathtt{font-family:KaTeX_Typewriter}.katex .mathscr{font-family:KaTeX_Script}.katex .mathsf{font-family:KaTeX_SansSerif}.katex .mainit{font-family:KaTeX_Main;font-style:italic}.katex .textstyle>.mord+.mop{margin-left:.16667em}.katex .textstyle>.mord+.mbin{margin-left:.22222em}.katex .textstyle>.mord+.mrel{margin-left:.27778em}.katex .textstyle>.mop+.mop,.katex .textstyle>.mop+.mord,.katex .textstyle>.mord+.minner{margin-left:.16667em}.katex .textstyle>.mop+.mrel{margin-left:.27778em}.katex .textstyle>.mop+.minner{margin-left:.16667em}.katex .textstyle>.mbin+.minner,.katex .textstyle>.mbin+.mop,.katex .textstyle>.mbin+.mopen,.katex .textstyle>.mbin+.mord{margin-left:.22222em}.katex .textstyle>.mrel+.minner,.katex .textstyle>.mrel+.mop,.katex .textstyle>.mrel+.mopen,.katex .textstyle>.mrel+.mord{margin-left:.27778em}.katex .textstyle>.mclose+.mop{margin-left:.16667em}.katex .textstyle>.mclose+.mbin{margin-left:.22222em}.katex .textstyle>.mclose+.mrel{margin-left:.27778em}.katex .textstyle>.mclose+.minner,.katex .textstyle>.minner+.mop,.katex .textstyle>.minner+.mord,.katex .textstyle>.mpunct+.mclose,.katex .textstyle>.mpunct+.minner,.katex .textstyle>.mpunct+.mop,.katex .textstyle>.mpunct+.mopen,.katex .textstyle>.mpunct+.mord,.katex .textstyle>.mpunct+.mpunct,.katex .textstyle>.mpunct+.mrel{margin-left:.16667em}.katex .textstyle>.minner+.mbin{margin-left:.22222em}.katex .textstyle>.minner+.mrel{margin-left:.27778em}.katex .mclose+.mop,.katex .minner+.mop,.katex .mop+.mop,.katex .mop+.mord,.katex .mord+.mop,.katex .textstyle>.minner+.minner,.katex .textstyle>.minner+.mopen,.katex .textstyle>.minner+.mpunct{margin-left:.16667em}.katex .reset-textstyle.textstyle{font-size:1em}.katex .reset-textstyle.scriptstyle{font-size:.7em}.katex .reset-textstyle.scriptscriptstyle{font-size:.5em}.katex .reset-scriptstyle.textstyle{font-size:1.42857em}.katex .reset-scriptstyle.scriptstyle{font-size:1em}.katex .reset-scriptstyle.scriptscriptstyle{font-size:.71429em}.katex .reset-scriptscriptstyle.textstyle{font-size:2em}.katex .reset-scriptscriptstyle.scriptstyle{font-size:1.4em}.katex .reset-scriptscriptstyle.scriptscriptstyle{font-size:1em}.katex .style-wrap{position:relative}.katex .vlist{display:inline-block}.katex .vlist>span{display:block;height:0;position:relative}.katex .vlist>span>span{display:inline-block}.katex .vlist .baseline-fix{display:inline-table;table-layout:fixed}.katex .msupsub{text-align:left}.katex .mfrac>span>span{text-align:center}.katex .mfrac .frac-line{width:100%}.katex .mfrac .frac-line:before{border-bottom-style:solid;border-bottom-width:1px;content:"";display:block}.katex .mfrac .frac-line:after{border-bottom-style:solid;border-bottom-width:.04em;content:"";display:block;margin-top:-1px}.katex .mspace{display:inline-block}.katex .mspace.negativethinspace{margin-left:-.16667em}.katex .mspace.thinspace{width:.16667em}.katex .mspace.mediumspace{width:.22222em}.katex .mspace.thickspace{width:.27778em}.katex .mspace.enspace{width:.5em}.katex .mspace.quad{width:1em}.katex .mspace.qquad{width:2em}.katex .llap,.katex .rlap{width:0;position:relative}.katex .llap>.inner,.katex .rlap>.inner{position:absolute}.katex .llap>.fix,.katex .rlap>.fix{display:inline-block}.katex .llap>.inner{right:0}.katex .rlap>.inner{left:0}.katex .katex-logo .a{font-size:.75em;margin-left:-.32em;position:relative;top:-.2em}.katex .katex-logo .t{margin-left:-.23em}.katex .katex-logo .e{margin-left:-.1667em;position:relative;top:.2155em}.katex .katex-logo .x{margin-left:-.125em}.katex .rule{display:inline-block;border-style:solid;position:relative}.katex .overline .overline-line{width:100%}.katex .overline .overline-line:before{border-bottom-style:solid;border-bottom-width:1px;content:"";display:block}.katex .overline .overline-line:after{border-bottom-style:solid;border-bottom-width:.04em;content:"";display:block;margin-top:-1px}.katex .sqrt>.sqrt-sign{position:relative}.katex .sqrt .sqrt-line{width:100%}.katex .sqrt .sqrt-line:before{border-bottom-style:solid;border-bottom-width:1px;content:"";display:block}.katex .sqrt .sqrt-line:after{border-bottom-style:solid;border-bottom-width:.04em;content:"";display:block;margin-top:-1px}.katex .sqrt>.root{margin-left:.27777778em;margin-right:-.55555556em}.katex .fontsize-ensurer,.katex .sizing{display:inline-block}.katex .fontsize-ensurer.reset-size1.size1,.katex .sizing.reset-size1.size1{font-size:1em}.katex .fontsize-ensurer.reset-size1.size2,.katex .sizing.reset-size1.size2{font-size:1.4em}.katex .fontsize-ensurer.reset-size1.size3,.katex .sizing.reset-size1.size3{font-size:1.6em}.katex .fontsize-ensurer.reset-size1.size4,.katex .sizing.reset-size1.size4{font-size:1.8em}.katex .fontsize-ensurer.reset-size1.size5,.katex .sizing.reset-size1.size5{font-size:2em}.katex .fontsize-ensurer.reset-size1.size6,.katex .sizing.reset-size1.size6{font-size:2.4em}.katex .fontsize-ensurer.reset-size1.size7,.katex .sizing.reset-size1.size7{font-size:2.88em}.katex .fontsize-ensurer.reset-size1.size8,.katex .sizing.reset-size1.size8{font-size:3.46em}.katex .fontsize-ensurer.reset-size1.size9,.katex .sizing.reset-size1.size9{font-size:4.14em}.katex .fontsize-ensurer.reset-size1.size10,.katex .sizing.reset-size1.size10{font-size:4.98em}.katex .fontsize-ensurer.reset-size2.size1,.katex .sizing.reset-size2.size1{font-size:.71428571em}.katex .fontsize-ensurer.reset-size2.size2,.katex .sizing.reset-size2.size2{font-size:1em}.katex .fontsize-ensurer.reset-size2.size3,.katex .sizing.reset-size2.size3{font-size:1.14285714em}.katex .fontsize-ensurer.reset-size2.size4,.katex .sizing.reset-size2.size4{font-size:1.28571429em}.katex .fontsize-ensurer.reset-size2.size5,.katex .sizing.reset-size2.size5{font-size:1.42857143em}.katex .fontsize-ensurer.reset-size2.size6,.katex .sizing.reset-size2.size6{font-size:1.71428571em}.katex .fontsize-ensurer.reset-size2.size7,.katex .sizing.reset-size2.size7{font-size:2.05714286em}.katex .fontsize-ensurer.reset-size2.size8,.katex .sizing.reset-size2.size8{font-size:2.47142857em}.katex .fontsize-ensurer.reset-size2.size9,.katex .sizing.reset-size2.size9{font-size:2.95714286em}.katex .fontsize-ensurer.reset-size2.size10,.katex .sizing.reset-size2.size10{font-size:3.55714286em}.katex .fontsize-ensurer.reset-size3.size1,.katex .sizing.reset-size3.size1{font-size:.625em}.katex .fontsize-ensurer.reset-size3.size2,.katex .sizing.reset-size3.size2{font-size:.875em}.katex .fontsize-ensurer.reset-size3.size3,.katex .sizing.reset-size3.size3{font-size:1em}.katex .fontsize-ensurer.reset-size3.size4,.katex .sizing.reset-size3.size4{font-size:1.125em}.katex .fontsize-ensurer.reset-size3.size5,.katex .sizing.reset-size3.size5{font-size:1.25em}.katex .fontsize-ensurer.reset-size3.size6,.katex .sizing.reset-size3.size6{font-size:1.5em}.katex .fontsize-ensurer.reset-size3.size7,.katex .sizing.reset-size3.size7{font-size:1.8em}.katex .fontsize-ensurer.reset-size3.size8,.katex .sizing.reset-size3.size8{font-size:2.1625em}.katex .fontsize-ensurer.reset-size3.size9,.katex .sizing.reset-size3.size9{font-size:2.5875em}.katex .fontsize-ensurer.reset-size3.size10,.katex .sizing.reset-size3.size10{font-size:3.1125em}.katex .fontsize-ensurer.reset-size4.size1,.katex .sizing.reset-size4.size1{font-size:.55555556em}.katex .fontsize-ensurer.reset-size4.size2,.katex .sizing.reset-size4.size2{font-size:.77777778em}.katex .fontsize-ensurer.reset-size4.size3,.katex .sizing.reset-size4.size3{font-size:.88888889em}.katex .fontsize-ensurer.reset-size4.size4,.katex .sizing.reset-size4.size4{font-size:1em}.katex .fontsize-ensurer.reset-size4.size5,.katex .sizing.reset-size4.size5{font-size:1.11111111em}.katex .fontsize-ensurer.reset-size4.size6,.katex .sizing.reset-size4.size6{font-size:1.33333333em}.katex .fontsize-ensurer.reset-size4.size7,.katex .sizing.reset-size4.size7{font-size:1.6em}.katex .fontsize-ensurer.reset-size4.size8,.katex .sizing.reset-size4.size8{font-size:1.92222222em}.katex .fontsize-ensurer.reset-size4.size9,.katex .sizing.reset-size4.size9{font-size:2.3em}.katex .fontsize-ensurer.reset-size4.size10,.katex .sizing.reset-size4.size10{font-size:2.76666667em}.katex .fontsize-ensurer.reset-size5.size1,.katex .sizing.reset-size5.size1{font-size:.5em}.katex .fontsize-ensurer.reset-size5.size2,.katex .sizing.reset-size5.size2{font-size:.7em}.katex .fontsize-ensurer.reset-size5.size3,.katex .sizing.reset-size5.size3{font-size:.8em}.katex .fontsize-ensurer.reset-size5.size4,.katex .sizing.reset-size5.size4{font-size:.9em}.katex .fontsize-ensurer.reset-size5.size5,.katex .sizing.reset-size5.size5{font-size:1em}.katex .fontsize-ensurer.reset-size5.size6,.katex .sizing.reset-size5.size6{font-size:1.2em}.katex .fontsize-ensurer.reset-size5.size7,.katex .sizing.reset-size5.size7{font-size:1.44em}.katex .fontsize-ensurer.reset-size5.size8,.katex .sizing.reset-size5.size8{font-size:1.73em}.katex .fontsize-ensurer.reset-size5.size9,.katex .sizing.reset-size5.size9{font-size:2.07em}.katex .fontsize-ensurer.reset-size5.size10,.katex .sizing.reset-size5.size10{font-size:2.49em}.katex .fontsize-ensurer.reset-size6.size1,.katex .sizing.reset-size6.size1{font-size:.41666667em}.katex .fontsize-ensurer.reset-size6.size2,.katex .sizing.reset-size6.size2{font-size:.58333333em}.katex .fontsize-ensurer.reset-size6.size3,.katex .sizing.reset-size6.size3{font-size:.66666667em}.katex .fontsize-ensurer.reset-size6.size4,.katex .sizing.reset-size6.size4{font-size:.75em}.katex .fontsize-ensurer.reset-size6.size5,.katex .sizing.reset-size6.size5{font-size:.83333333em}.katex .fontsize-ensurer.reset-size6.size6,.katex .sizing.reset-size6.size6{font-size:1em}.katex .fontsize-ensurer.reset-size6.size7,.katex .sizing.reset-size6.size7{font-size:1.2em}.katex .fontsize-ensurer.reset-size6.size8,.katex .sizing.reset-size6.size8{font-size:1.44166667em}.katex .fontsize-ensurer.reset-size6.size9,.katex .sizing.reset-size6.size9{font-size:1.725em}.katex .fontsize-ensurer.reset-size6.size10,.katex .sizing.reset-size6.size10{font-size:2.075em}.katex .fontsize-ensurer.reset-size7.size1,.katex .sizing.reset-size7.size1{font-size:.34722222em}.katex .fontsize-ensurer.reset-size7.size2,.katex .sizing.reset-size7.size2{font-size:.48611111em}.katex .fontsize-ensurer.reset-size7.size3,.katex .sizing.reset-size7.size3{font-size:.55555556em}.katex .fontsize-ensurer.reset-size7.size4,.katex .sizing.reset-size7.size4{font-size:.625em}.katex .fontsize-ensurer.reset-size7.size5,.katex .sizing.reset-size7.size5{font-size:.69444444em}.katex .fontsize-ensurer.reset-size7.size6,.katex .sizing.reset-size7.size6{font-size:.83333333em}.katex .fontsize-ensurer.reset-size7.size7,.katex .sizing.reset-size7.size7{font-size:1em}.katex .fontsize-ensurer.reset-size7.size8,.katex .sizing.reset-size7.size8{font-size:1.20138889em}.katex .fontsize-ensurer.reset-size7.size9,.katex .sizing.reset-size7.size9{font-size:1.4375em}.katex .fontsize-ensurer.reset-size7.size10,.katex .sizing.reset-size7.size10{font-size:1.72916667em}.katex .fontsize-ensurer.reset-size8.size1,.katex .sizing.reset-size8.size1{font-size:.28901734em}.katex .fontsize-ensurer.reset-size8.size2,.katex .sizing.reset-size8.size2{font-size:.40462428em}.katex .fontsize-ensurer.reset-size8.size3,.katex .sizing.reset-size8.size3{font-size:.46242775em}.katex .fontsize-ensurer.reset-size8.size4,.katex .sizing.reset-size8.size4{font-size:.52023121em}.katex .fontsize-ensurer.reset-size8.size5,.katex .sizing.reset-size8.size5{font-size:.57803468em}.katex .fontsize-ensurer.reset-size8.size6,.katex .sizing.reset-size8.size6{font-size:.69364162em}.katex .fontsize-ensurer.reset-size8.size7,.katex .sizing.reset-size8.size7{font-size:.83236994em}.katex .fontsize-ensurer.reset-size8.size8,.katex .sizing.reset-size8.size8{font-size:1em}.katex .fontsize-ensurer.reset-size8.size9,.katex .sizing.reset-size8.size9{font-size:1.19653179em}.katex .fontsize-ensurer.reset-size8.size10,.katex .sizing.reset-size8.size10{font-size:1.43930636em}.katex .fontsize-ensurer.reset-size9.size1,.katex .sizing.reset-size9.size1{font-size:.24154589em}.katex .fontsize-ensurer.reset-size9.size2,.katex .sizing.reset-size9.size2{font-size:.33816425em}.katex .fontsize-ensurer.reset-size9.size3,.katex .sizing.reset-size9.size3{font-size:.38647343em}.katex .fontsize-ensurer.reset-size9.size4,.katex .sizing.reset-size9.size4{font-size:.43478261em}.katex .fontsize-ensurer.reset-size9.size5,.katex .sizing.reset-size9.size5{font-size:.48309179em}.katex .fontsize-ensurer.reset-size9.size6,.katex .sizing.reset-size9.size6{font-size:.57971014em}.katex .fontsize-ensurer.reset-size9.size7,.katex .sizing.reset-size9.size7{font-size:.69565217em}.katex .fontsize-ensurer.reset-size9.size8,.katex .sizing.reset-size9.size8{font-size:.83574879em}.katex .fontsize-ensurer.reset-size9.size9,.katex .sizing.reset-size9.size9{font-size:1em}.katex .fontsize-ensurer.reset-size9.size10,.katex .sizing.reset-size9.size10{font-size:1.20289855em}.katex .fontsize-ensurer.reset-size10.size1,.katex .sizing.reset-size10.size1{font-size:.20080321em}.katex .fontsize-ensurer.reset-size10.size2,.katex .sizing.reset-size10.size2{font-size:.2811245em}.katex .fontsize-ensurer.reset-size10.size3,.katex .sizing.reset-size10.size3{font-size:.32128514em}.katex .fontsize-ensurer.reset-size10.size4,.katex .sizing.reset-size10.size4{font-size:.36144578em}.katex .fontsize-ensurer.reset-size10.size5,.katex .sizing.reset-size10.size5{font-size:.40160643em}.katex .fontsize-ensurer.reset-size10.size6,.katex .sizing.reset-size10.size6{font-size:.48192771em}.katex .fontsize-ensurer.reset-size10.size7,.katex .sizing.reset-size10.size7{font-size:.57831325em}.katex .fontsize-ensurer.reset-size10.size8,.katex .sizing.reset-size10.size8{font-size:.69477912em}.katex .fontsize-ensurer.reset-size10.size9,.katex .sizing.reset-size10.size9{font-size:.8313253em}.katex .fontsize-ensurer.reset-size10.size10,.katex .sizing.reset-size10.size10{font-size:1em}.katex .delimsizing.size1{font-family:KaTeX_Size1}.katex .delimsizing.size2{font-family:KaTeX_Size2}.katex .delimsizing.size3{font-family:KaTeX_Size3}.katex .delimsizing.size4{font-family:KaTeX_Size4}.katex .delimsizing.mult .delim-size1>span{font-family:KaTeX_Size1}.katex .delimsizing.mult .delim-size4>span{font-family:KaTeX_Size4}.katex .nulldelimiter{display:inline-block;width:.12em}.katex .op-symbol{position:relative}.katex .op-symbol.small-op{font-family:KaTeX_Size1}.katex .op-symbol.large-op{font-family:KaTeX_Size2}.katex .accent>.vlist>span,.katex .op-limits>.vlist>span{text-align:center}.katex .accent .accent-body>span{width:0}.katex .accent .accent-body.accent-vec>span{position:relative;left:.326em}.katex .mtable .vertical-separator{display:inline-block;margin:0 -.025em;border-right:.05em solid #000}.katex .mtable .arraycolsep{display:inline-block}.katex .mtable .col-align-c>.vlist{text-align:center}.katex .mtable .col-align-l>.vlist{text-align:left}.katex .mtable .col-align-r>.vlist{text-align:right} diff --git a/src/service/MarkdownService.ts b/src/service/MarkdownService.ts index 29c6280..26a0ea0 100644 --- a/src/service/MarkdownService.ts +++ b/src/service/MarkdownService.ts @@ -9,6 +9,7 @@ import * as hljs from "highlight.js"; import * as MarkdownIt from "markdown-it"; +import * as MarkDownItKatex from "markdown-it-katex"; import * as os from "os"; import * as path from "path"; import * as vscode from "vscode"; @@ -30,7 +31,10 @@ class MarkdownService implements vscode.Disposable { } public get localResourceRoots(): vscode.Uri[] { - return [vscode.Uri.file(path.join(this.config.extRoot, "media"))]; + return [ + vscode.Uri.file(path.join(this.config.extRoot, "media")), + vscode.Uri.file(path.join(__dirname, "..", "..", "..", "resources", "katexcss")), + ]; } public dispose(): void { @@ -108,6 +112,7 @@ class MarkdownService implements vscode.Disposable { }, }); + md.use(MarkDownItKatex); this.addCodeBlockHighlight(md); this.addImageUrlCompletion(md); this.addLinkValidator(md); diff --git a/src/service/SolutionService.ts b/src/service/SolutionService.ts index 73af3e8..cbf3085 100644 --- a/src/service/SolutionService.ts +++ b/src/service/SolutionService.ts @@ -13,6 +13,8 @@ import { BaseWebViewService } from "./BaseWebviewService"; import { markdownService } from "./MarkdownService"; import { IWebViewOption } from "../model/Model"; +import * as path from "path"; + class SolutionService extends BaseWebViewService { protected readonly viewType: string = "leetcode.solution"; private problemName: string; @@ -52,16 +54,32 @@ class SolutionService extends BaseWebViewService { `| ${lang} | ${auth} | ${votes} |`, ].join("\n") ); + + // $\textit + this.solution.body = this.solution.body.replace(/\$\textit/g, "$"); + const body: string = markdownService.render(this.solution.body, { lang: this.solution.lang, host: "https://discuss.leetcode.com/", }); + // "\n\n" + // + return ` - + ${styles} + ${head} From e8eb76faf7802f32042910254ddb0a3e48aa7227 Mon Sep 17 00:00:00 2001 From: ccagml Date: Sat, 28 Jan 2023 17:13:21 +0800 Subject: [PATCH 03/11] markdown-it-katex --- package-lock.json | 50 +++++++++++++++++++++++++++++++++++++++++++++-- package.json | 1 + 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7455b8f..d0282a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-leetcode-problem-rating", - "version": "2.12.2", + "version": "2.13.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-leetcode-problem-rating", - "version": "2.12.2", + "version": "2.13.1", "license": "MIT", "dependencies": { "ansi-styles": "3.2.1", @@ -16,6 +16,7 @@ "highlight.js": "^10.7.2", "lodash": "^4.17.21", "markdown-it": "12.3.2", + "markdown-it-katex": "^2.0.3", "mkdirp": "^1.0.4", "moment": "^2.29.1", "nconf": "^0.11.2", @@ -1844,6 +1845,17 @@ "node": ">=0.6.0" } }, + "node_modules/katex": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/katex/-/katex-0.6.0.tgz", + "integrity": "sha512-rS4mY3SvHYg5LtQV6RBcK0if7ur6plyEukAOV+jGGPqFImuzu8fHL6M752iBmRGoUyF0bhZbAPoezehn7xYksA==", + "dependencies": { + "match-at": "^0.1.0" + }, + "bin": { + "katex": "cli.js" + } + }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -1918,6 +1930,14 @@ "markdown-it": "bin/markdown-it.js" } }, + "node_modules/markdown-it-katex": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/markdown-it-katex/-/markdown-it-katex-2.0.3.tgz", + "integrity": "sha512-nUkkMtRWeg7OpdflamflE/Ho/pWl64Lk9wNBKOmaj33XkQdumhXAIYhI0WO03GeiycPCsxbmX536V5NEXpC3Ng==", + "dependencies": { + "katex": "^0.6.0" + } + }, "node_modules/markdown-it/node_modules/entities": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz", @@ -1926,6 +1946,11 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/match-at": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/match-at/-/match-at-0.1.1.tgz", + "integrity": "sha512-h4Yd392z9mST+dzc+yjuybOGFNOZjmXIPKWjxBd1Bb23r4SmDOsk2NYCU2BMUBGbSpZqwVsZYNq26QS3xfaT3Q==" + }, "node_modules/mdurl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", @@ -4408,6 +4433,14 @@ "verror": "1.10.0" } }, + "katex": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/katex/-/katex-0.6.0.tgz", + "integrity": "sha512-rS4mY3SvHYg5LtQV6RBcK0if7ur6plyEukAOV+jGGPqFImuzu8fHL6M752iBmRGoUyF0bhZbAPoezehn7xYksA==", + "requires": { + "match-at": "^0.1.0" + } + }, "levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -4474,6 +4507,19 @@ } } }, + "markdown-it-katex": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/markdown-it-katex/-/markdown-it-katex-2.0.3.tgz", + "integrity": "sha512-nUkkMtRWeg7OpdflamflE/Ho/pWl64Lk9wNBKOmaj33XkQdumhXAIYhI0WO03GeiycPCsxbmX536V5NEXpC3Ng==", + "requires": { + "katex": "^0.6.0" + } + }, + "match-at": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/match-at/-/match-at-0.1.1.tgz", + "integrity": "sha512-h4Yd392z9mST+dzc+yjuybOGFNOZjmXIPKWjxBd1Bb23r4SmDOsk2NYCU2BMUBGbSpZqwVsZYNq26QS3xfaT3Q==" + }, "mdurl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", diff --git a/package.json b/package.json index a540a1b..485d90e 100644 --- a/package.json +++ b/package.json @@ -1134,6 +1134,7 @@ "highlight.js": "^10.7.2", "lodash": "^4.17.21", "markdown-it": "12.3.2", + "markdown-it-katex": "^2.0.3", "mkdirp": "^1.0.4", "moment": "^2.29.1", "nconf": "^0.11.2", From 35cee96598c48cbc821df52776c0ecc1e80dc75e Mon Sep 17 00:00:00 2001 From: ccagml Date: Sun, 29 Jan 2023 15:45:58 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=93=E5=BC=80=20ap?= =?UTF-8?q?p=20=E6=B8=85=E7=A9=BA=E9=A2=98=E7=9B=AE=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=85=8D=E7=BD=AE(=E9=BB=98=E8=AE=A4=E5=85=B3=E9=97=AD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ package.json | 14 ++++++++++++- src/controller/MainController.ts | 8 +++++++ src/extension.ts | 1 + src/rpc/factory/api/cacheApi.ts | 36 +++++++++++++++++++++++++------- src/rpc/utils/storageUtils.ts | 5 ++--- src/service/ExecuteService.ts | 19 +++++++++++++++++ src/utils/ConfigUtils.ts | 10 +++++++++ 8 files changed, 86 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4d97bc..0f25131 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## version 2.13.2 + +- 增加打开 app 清空题目缓存配置(默认关闭),避免题目缓存数据不同步 + ## version 2.13.1 - 题解显示 katex 数学公式 diff --git a/package.json b/package.json index 485d90e..e7d4124 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-leetcode-problem-rating", "displayName": "LeetCode", "description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了", - "version": "2.13.1", + "version": "2.13.2", "author": "ccagml", "publisher": "ccagml", "license": "MIT", @@ -1101,6 +1101,18 @@ ], "scope": "application", "description": "Precinct Score Hidden Questions." + }, + "leetcode-problem-rating.openClearProblemCache": { + "type": "boolean", + "default": false, + "scope": "application", + "description": "Clear the Problems cache when opening the app to avoid out-of-sync state" + }, + "leetcode-problem-rating.openClearProblemCacheTime": { + "type": "integer", + "default": 3600, + "scope": "application", + "description": "Open the app to clear the cache interval by default 3600 seconds" } } } diff --git a/src/controller/MainController.ts b/src/controller/MainController.ts index c61b8a1..9bc5bb8 100644 --- a/src/controller/MainController.ts +++ b/src/controller/MainController.ts @@ -32,6 +32,14 @@ class MainContorller { } } + /** + * 检查题目缓存 + */ + + public async deleteProblemCache() { + await executeService.deleteProblemCache(); + } + /** * It takes the version number from the package.json file and converts it to a number * @param {ExtensionContext} context - ExtensionContext diff --git a/src/extension.ts b/src/extension.ts index 1da6a9c..e968a37 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -43,6 +43,7 @@ export async function activate(context: ExtensionContext): Promise { mainContorller.initialize(context); // 检查node环境 await mainContorller.checkNodeEnv(context); + await mainContorller.deleteProblemCache(); // 事件监听 eventController.addEvent(); diff --git a/src/rpc/factory/api/cacheApi.ts b/src/rpc/factory/api/cacheApi.ts index 841e3fc..cf9b45e 100644 --- a/src/rpc/factory/api/cacheApi.ts +++ b/src/rpc/factory/api/cacheApi.ts @@ -10,6 +10,7 @@ import { storageUtils } from "../../utils/storageUtils"; import { sessionUtils } from "../../utils/sessionUtils"; import { ApiBase } from "../apiBase"; +import { reply } from "../../utils/ReplyUtils"; class CacheApi extends ApiBase { constructor() { @@ -17,12 +18,24 @@ class CacheApi extends ApiBase { } callArg(argv) { - let argv_config = this.api_argv().option("d", { - alias: "delete", - type: "boolean", - describe: "Delete cache by keyword", - default: false, - }); + let argv_config = this.api_argv() + .option("d", { + alias: "delete", + type: "boolean", + describe: "Delete cache by keyword", + default: false, + }) + .option("t", { + alias: "lastmodify", + type: "string", + default: "", + describe: "", + }) + .positional("keyword", { + type: "string", + default: "", + describe: "帮助的参数?", + }); argv_config.parseArgFromCmd(argv); return argv_config.get_result(); @@ -34,15 +47,24 @@ class CacheApi extends ApiBase { const name = argv.keyword || ""; const isInteger = Number.isInteger(Number(name)); + let option_t = Number(argv.t); + const need_last_modify_time = Number.isInteger(option_t); + if (need_last_modify_time) { + option_t *= 1000; + } const all_data_file = storageUtils.listCache().filter(function (f) { return name.length === 0 || (isInteger ? f.name.startsWith(name + ".") : f.name === name); }); if (argv.delete) { + const cur_time = new Date().getTime(); for (let f of all_data_file) { - storageUtils.delCache(f.name); + if (!need_last_modify_time || (f.mtimeMs || 0) + option_t < cur_time) { + storageUtils.delCache(f.name); + } } } + reply.info(JSON.stringify({ code: 100 })); } } diff --git a/src/rpc/utils/storageUtils.ts b/src/rpc/utils/storageUtils.ts index 39a24e5..3bef620 100644 --- a/src/rpc/utils/storageUtils.ts +++ b/src/rpc/utils/storageUtils.ts @@ -266,6 +266,7 @@ class StorageUtils { name: k, size: stat.size, mtime: stat.mtime, + mtimeMs: stat.mtimeMs, }; }); } @@ -463,7 +464,6 @@ class StorageUtils { return lineContent.substring(cut_pos); } - public meta(filename) { const m = Object.assign({}, defaultMETA, {}); @@ -476,8 +476,7 @@ class StorageUtils { for (let all_input = 0; all_input < file_info.length; all_input++) { const lineContent = file_info[all_input]; if (caseFlag && lineContent.indexOf("@lcpr case=end") < 0) { - curCase += this.fix_lineContent(lineContent).replace(/\s+/g, "") - .replace(/\\n/g, "\n"); + curCase += this.fix_lineContent(lineContent).replace(/\s+/g, "").replace(/\\n/g, "\n"); } // 收集所有用例 if (lineContent.indexOf("@lcpr case=start") >= 0) { diff --git a/src/service/ExecuteService.ts b/src/service/ExecuteService.ts index 1269e27..8b53351 100644 --- a/src/service/ExecuteService.ts +++ b/src/service/ExecuteService.ts @@ -19,6 +19,7 @@ import { getNodePath } from "../utils/ConfigUtils"; import { openUrl, promptForOpenOutputChannel } from "../utils/OutputUtils"; import * as systemUtils from "../utils/SystemUtils"; import { toWslPath, useWsl } from "../utils/SystemUtils"; +import { getOpenClearProblemCacheTime, isOpenClearProblemCache } from "../utils/ConfigUtils"; class ExecuteService implements Disposable { private leetCodeCliResourcesRootPath: string; @@ -82,6 +83,24 @@ class ExecuteService implements Disposable { return true; } + // 多机同步,可能题目缓存会导致不一致 + public async deleteProblemCache() { + if (isOpenClearProblemCache()) { + try { + await this.executeCommandWithProgressEx("正在清除缓存~", this.nodeExecutable, [ + await this.getLeetCodeBinaryPath(), + "cache", + "-d", + "problems", + "-t", + getOpenClearProblemCacheTime().toString(), + ]); + } catch (error) { + await promptForOpenOutputChannel("Failed to delete cache. 请查看控制台信息~", OutPutType.error); + } + } + } + public async deleteCache() { try { await this.executeCommandWithProgressEx("正在清除缓存~", this.nodeExecutable, [ diff --git a/src/utils/ConfigUtils.ts b/src/utils/ConfigUtils.ts index 38251ac..f6ca700 100644 --- a/src/utils/ConfigUtils.ts +++ b/src/utils/ConfigUtils.ts @@ -383,3 +383,13 @@ export function getIncludeTemplate(lang: string): string { return result; } + +// 获取清除缓存修改时间间隔 +export function getOpenClearProblemCacheTime(): number { + return getVsCodeConfig().get("openClearProblemCacheTime") || 3600; +} + +// 是否打开清除题目缓存 +export function isOpenClearProblemCache(): boolean { + return getVsCodeConfig().get("openClearProblemCache", false); +} From a7342bb289fb687b977491408d10bd368bb0b79c Mon Sep 17 00:00:00 2001 From: ccagml Date: Sun, 29 Jan 2023 22:29:51 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E6=94=B9=E4=B8=AA=E5=BD=A2=E8=B1=A1?= =?UTF-8?q?=E7=9A=84=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ README.md | 8 ++++---- package.json | 6 +++--- src/controller/BricksViewController.ts | 4 ++-- src/controller/EventController.ts | 4 ++-- src/controller/FileButtonController.ts | 4 ++-- src/controller/LoginController.ts | 4 ++-- src/controller/MainController.ts | 4 ++-- src/controller/RemarkController.ts | 4 ++-- src/controller/TreeViewController.ts | 4 ++-- src/dao/bricksDao.ts | 4 ++-- src/dao/choiceDao.ts | 4 ++-- src/dao/groupDao.ts | 4 ++-- src/dao/scoreDao.ts | 4 ++-- src/dao/tagsDao.ts | 4 ++-- src/extension.ts | 4 ++-- src/model/Model.ts | 4 ++-- src/model/NodeModel.ts | 4 ++-- src/rpc/actionChain/chainManager.ts | 4 ++-- src/rpc/actionChain/chainNode/cache.ts | 4 ++-- src/rpc/actionChain/chainNode/core.ts | 4 ++-- src/rpc/actionChain/chainNode/leetcode.cn.ts | 4 ++-- src/rpc/actionChain/chainNode/leetcode.ts | 4 ++-- src/rpc/actionChain/chainNode/retry.ts | 4 ++-- src/rpc/childMain.ts | 4 ++-- src/rpc/factory/api/cacheApi.ts | 4 ++-- src/rpc/factory/api/pluginApi.ts | 4 ++-- src/rpc/factory/api/queryApi.ts | 4 ++-- src/rpc/factory/api/showApi.ts | 4 ++-- src/rpc/factory/api/starApi.ts | 4 ++-- src/rpc/factory/api/submitApi.ts | 4 ++-- src/rpc/factory/api/testApi.ts | 4 ++-- src/rpc/factory/api/userApi.ts | 4 ++-- src/rpc/factory/apiBase.ts | 4 ++-- src/rpc/utils/ReplyUtils.ts | 4 ++-- src/rpc/utils/commUtils.ts | 4 ++-- src/rpc/utils/configUtils.ts | 4 ++-- src/rpc/utils/queueUtils.ts | 4 ++-- src/rpc/utils/sessionUtils.ts | 4 ++-- src/rpc/utils/storageUtils.ts | 4 ++-- src/service/BaseWebviewService.ts | 4 ++-- src/service/BricksDataService.ts | 4 ++-- src/service/EventService.ts | 4 ++-- src/service/ExecuteService.ts | 4 ++-- src/service/FileButtonService.ts | 4 ++-- src/service/MarkdownService.ts | 4 ++-- src/service/PreviewService.ts | 4 ++-- src/service/SolutionService.ts | 4 ++-- src/service/StatusBarService.ts | 4 ++-- src/service/StatusBarTimeService.ts | 4 ++-- src/service/SubmissionService.ts | 4 ++-- src/service/TreeDataService.ts | 4 ++-- src/service/TreeItemDecorationService.ts | 4 ++-- src/utils/CliUtils.ts | 4 ++-- src/utils/ConfigUtils.ts | 4 ++-- src/utils/OutputUtils.ts | 4 ++-- src/utils/SystemUtils.ts | 4 ++-- 57 files changed, 119 insertions(+), 115 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f25131..05b8c1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## version 2.13.3 + +- 修改README.md + ## version 2.13.2 - 增加打开 app 清空题目缓存配置(默认关闭),避免题目缓存数据不同步 diff --git a/README.md b/README.md index 91329ab..e0705ac 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@

- + - +

@@ -31,8 +31,8 @@ # 关于本项目 -- [项目地址:https://github.com/ccagml/leetcode-vscode/](https://github.com/ccagml/leetcode-vscode/) -- [报告问题](https://github.com/ccagml/leetcode-vscode/issues) +- [项目地址:https://github.com/ccagml/leetcode_extension/](https://github.com/ccagml/leetcode_extension/) +- [报告问题](https://github.com/ccagml/leetcode_extension/issues) - [疑难解答](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/%E7%96%91%E9%9A%BE%E8%A7%A3%E7%AD%94) - [常见问题](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98) - 趁着现在只有提交一个 PR 就能成为项目元老了 diff --git a/package.json b/package.json index e7d4124..ceaa212 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-leetcode-problem-rating", "displayName": "LeetCode", "description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了", - "version": "2.13.2", + "version": "2.13.3", "author": "ccagml", "publisher": "ccagml", "license": "MIT", @@ -12,9 +12,9 @@ }, "repository": { "type": "git", - "url": "https://github.com/ccagml/leetcode-vscode" + "url": "https://github.com/ccagml/leetcode_extension" }, - "homepage": "https://github.com/ccagml/leetcode-vscode/README.md", + "homepage": "https://github.com/ccagml/leetcode_extension/README.md", "categories": [ "Other", "Snippets", diff --git a/src/controller/BricksViewController.ts b/src/controller/BricksViewController.ts index a72c82d..75c958d 100644 --- a/src/controller/BricksViewController.ts +++ b/src/controller/BricksViewController.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/controller/BricksViewController.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/controller/BricksViewController.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Tuesday, November 22nd 2022, 11:04:59 am * Author: ccagml * diff --git a/src/controller/EventController.ts b/src/controller/EventController.ts index c9e7ecc..ee6c834 100644 --- a/src/controller/EventController.ts +++ b/src/controller/EventController.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/controller/EventController.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/controller/EventController.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, October 31st 2022, 10:16:47 am * Author: ccagml * diff --git a/src/controller/FileButtonController.ts b/src/controller/FileButtonController.ts index cc705d1..b41b087 100644 --- a/src/controller/FileButtonController.ts +++ b/src/controller/FileButtonController.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/controller/FileButtonController.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/controller/FileButtonController.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/controller/LoginController.ts b/src/controller/LoginController.ts index c27a001..2db8a55 100644 --- a/src/controller/LoginController.ts +++ b/src/controller/LoginController.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/controller/LoginController.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/controller/LoginController.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 10th 2022, 3:06:12 pm * Author: ccagml * diff --git a/src/controller/MainController.ts b/src/controller/MainController.ts index 9bc5bb8..9eca4bb 100644 --- a/src/controller/MainController.ts +++ b/src/controller/MainController.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/controller/MainController.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/controller/MainController.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 10th 2022, 2:18:21 pm * Author: ccagml * diff --git a/src/controller/RemarkController.ts b/src/controller/RemarkController.ts index eb29745..11b5de9 100644 --- a/src/controller/RemarkController.ts +++ b/src/controller/RemarkController.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/controller/RemarkController.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/controller/RemarkController.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, November 28th 2022, 3:29:37 pm * Author: ccagml * diff --git a/src/controller/TreeViewController.ts b/src/controller/TreeViewController.ts index b2a6f8f..676422f 100644 --- a/src/controller/TreeViewController.ts +++ b/src/controller/TreeViewController.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/controller/TreeViewController.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/controller/TreeViewController.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/dao/bricksDao.ts b/src/dao/bricksDao.ts index 24c57a9..433f1b4 100644 --- a/src/dao/bricksDao.ts +++ b/src/dao/bricksDao.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/dao/bricksDao.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/dao/bricksDao.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Wednesday, November 23rd 2022, 4:36:38 pm * Author: ccagml * diff --git a/src/dao/choiceDao.ts b/src/dao/choiceDao.ts index 27c738e..b3444f5 100644 --- a/src/dao/choiceDao.ts +++ b/src/dao/choiceDao.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/dao/choiceDao.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/dao/choiceDao.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 10th 2022, 11:34:10 pm * Author: ccagml * diff --git a/src/dao/groupDao.ts b/src/dao/groupDao.ts index 6010e2a..3cc6413 100644 --- a/src/dao/groupDao.ts +++ b/src/dao/groupDao.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/dao/groupDao.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/dao/groupDao.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Wednesday, November 30th 2022, 9:47:36 am * Author: ccagml * diff --git a/src/dao/scoreDao.ts b/src/dao/scoreDao.ts index 582bc17..ec1092a 100644 --- a/src/dao/scoreDao.ts +++ b/src/dao/scoreDao.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/dao/scoreDao.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/dao/scoreDao.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 10th 2022, 11:40:22 pm * Author: ccagml * diff --git a/src/dao/tagsDao.ts b/src/dao/tagsDao.ts index 378f1cd..717761f 100644 --- a/src/dao/tagsDao.ts +++ b/src/dao/tagsDao.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/dao/tagsDao.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/dao/tagsDao.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 10th 2022, 11:38:10 pm * Author: ccagml * diff --git a/src/extension.ts b/src/extension.ts index e968a37..4ab9dd7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/extension.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/extension.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, October 31st 2022, 10:16:47 am * Author: ccagml * diff --git a/src/model/Model.ts b/src/model/Model.ts index 2cc37f8..ec2c35b 100644 --- a/src/model/Model.ts +++ b/src/model/Model.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/model/Model.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/model/Model.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/model/NodeModel.ts b/src/model/NodeModel.ts index 0958a35..af65088 100644 --- a/src/model/NodeModel.ts +++ b/src/model/NodeModel.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/model/NodeMOdel.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/model/NodeMOdel.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/rpc/actionChain/chainManager.ts b/src/rpc/actionChain/chainManager.ts index bd854bd..15b2b7b 100644 --- a/src/rpc/actionChain/chainManager.ts +++ b/src/rpc/actionChain/chainManager.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/actionChain/chainMgr.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/actionChain/chainMgr.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, November 14th 2022, 4:04:31 pm * Author: ccagml * diff --git a/src/rpc/actionChain/chainNode/cache.ts b/src/rpc/actionChain/chainNode/cache.ts index 4a1210a..8cb2e53 100644 --- a/src/rpc/actionChain/chainNode/cache.ts +++ b/src/rpc/actionChain/chainNode/cache.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/actionChain/cache.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/actionChain/cache.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, November 14th 2022, 4:04:31 pm * Author: ccagml * diff --git a/src/rpc/actionChain/chainNode/core.ts b/src/rpc/actionChain/chainNode/core.ts index 703a41d..f493759 100644 --- a/src/rpc/actionChain/chainNode/core.ts +++ b/src/rpc/actionChain/chainNode/core.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/actionChain/core.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/actionChain/core.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, November 14th 2022, 4:04:31 pm * Author: ccagml * diff --git a/src/rpc/actionChain/chainNode/leetcode.cn.ts b/src/rpc/actionChain/chainNode/leetcode.cn.ts index 88a562f..9a15b66 100644 --- a/src/rpc/actionChain/chainNode/leetcode.cn.ts +++ b/src/rpc/actionChain/chainNode/leetcode.cn.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/actionChain/leetcode.cn.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/actionChain/leetcode.cn.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, November 14th 2022, 4:04:31 pm * Author: ccagml * diff --git a/src/rpc/actionChain/chainNode/leetcode.ts b/src/rpc/actionChain/chainNode/leetcode.ts index d409e5e..c83158f 100644 --- a/src/rpc/actionChain/chainNode/leetcode.ts +++ b/src/rpc/actionChain/chainNode/leetcode.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/actionChain/leetcode.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/actionChain/leetcode.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, November 14th 2022, 4:04:31 pm * Author: ccagml * diff --git a/src/rpc/actionChain/chainNode/retry.ts b/src/rpc/actionChain/chainNode/retry.ts index 8e8f9d3..946bfce 100644 --- a/src/rpc/actionChain/chainNode/retry.ts +++ b/src/rpc/actionChain/chainNode/retry.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/actionChain/retry.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/actionChain/retry.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, November 14th 2022, 4:04:31 pm * Author: ccagml * diff --git a/src/rpc/childMain.ts b/src/rpc/childMain.ts index 874d50f..c1ed3d3 100644 --- a/src/rpc/childMain.ts +++ b/src/rpc/childMain.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/rpc/cli.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/rpc/cli.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/rpc/factory/api/cacheApi.ts b/src/rpc/factory/api/cacheApi.ts index cf9b45e..1d2a723 100644 --- a/src/rpc/factory/api/cacheApi.ts +++ b/src/rpc/factory/api/cacheApi.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/factory/api/cacheApi.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/factory/api/cacheApi.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 17th 2022, 11:44:14 am * Author: ccagml * diff --git a/src/rpc/factory/api/pluginApi.ts b/src/rpc/factory/api/pluginApi.ts index 3601646..c03c1c5 100644 --- a/src/rpc/factory/api/pluginApi.ts +++ b/src/rpc/factory/api/pluginApi.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/factory/api/pluginApi.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/factory/api/pluginApi.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 17th 2022, 11:44:14 am * Author: ccagml * diff --git a/src/rpc/factory/api/queryApi.ts b/src/rpc/factory/api/queryApi.ts index 1da4461..57611a4 100644 --- a/src/rpc/factory/api/queryApi.ts +++ b/src/rpc/factory/api/queryApi.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/factory/api/queryApi.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/factory/api/queryApi.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 17th 2022, 11:44:14 am * Author: ccagml * diff --git a/src/rpc/factory/api/showApi.ts b/src/rpc/factory/api/showApi.ts index 4176dbc..525a1f1 100644 --- a/src/rpc/factory/api/showApi.ts +++ b/src/rpc/factory/api/showApi.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/factory/api/showApi.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/factory/api/showApi.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 17th 2022, 11:44:14 am * Author: ccagml * diff --git a/src/rpc/factory/api/starApi.ts b/src/rpc/factory/api/starApi.ts index d217428..fb0782a 100644 --- a/src/rpc/factory/api/starApi.ts +++ b/src/rpc/factory/api/starApi.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/factory/api/starApi.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/factory/api/starApi.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 17th 2022, 11:44:14 am * Author: ccagml * diff --git a/src/rpc/factory/api/submitApi.ts b/src/rpc/factory/api/submitApi.ts index 93919ce..2b16b74 100644 --- a/src/rpc/factory/api/submitApi.ts +++ b/src/rpc/factory/api/submitApi.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/factory/api/submitApi.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/factory/api/submitApi.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 17th 2022, 11:44:14 am * Author: ccagml * diff --git a/src/rpc/factory/api/testApi.ts b/src/rpc/factory/api/testApi.ts index 648f508..28b44ba 100644 --- a/src/rpc/factory/api/testApi.ts +++ b/src/rpc/factory/api/testApi.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/factory/api/testApi.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/factory/api/testApi.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 17th 2022, 11:44:14 am * Author: ccagml * diff --git a/src/rpc/factory/api/userApi.ts b/src/rpc/factory/api/userApi.ts index 00d3ba7..99d38fa 100644 --- a/src/rpc/factory/api/userApi.ts +++ b/src/rpc/factory/api/userApi.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/factory/api/userApi.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/factory/api/userApi.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 17th 2022, 11:44:14 am * Author: ccagml * diff --git a/src/rpc/factory/apiBase.ts b/src/rpc/factory/apiBase.ts index 9741ffd..e88b51e 100644 --- a/src/rpc/factory/apiBase.ts +++ b/src/rpc/factory/apiBase.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/factory/apiBase.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/factory/apiBase.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 17th 2022, 11:44:14 am * Author: ccagml * diff --git a/src/rpc/utils/ReplyUtils.ts b/src/rpc/utils/ReplyUtils.ts index f155176..046e31b 100644 --- a/src/rpc/utils/ReplyUtils.ts +++ b/src/rpc/utils/ReplyUtils.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/Response.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/Response.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, November 14th 2022, 4:04:31 pm * Author: ccagml * diff --git a/src/rpc/utils/commUtils.ts b/src/rpc/utils/commUtils.ts index 74a572a..ef13f48 100644 --- a/src/rpc/utils/commUtils.ts +++ b/src/rpc/utils/commUtils.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/rpc/commUtils.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/rpc/commUtils.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Wednesday, November 16th 2022, 4:50:55 pm * Author: ccagml * diff --git a/src/rpc/utils/configUtils.ts b/src/rpc/utils/configUtils.ts index 38cc9c4..5c143fa 100644 --- a/src/rpc/utils/configUtils.ts +++ b/src/rpc/utils/configUtils.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/rpc/config.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/rpc/config.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/rpc/utils/queueUtils.ts b/src/rpc/utils/queueUtils.ts index 2b533e5..47aeb8d 100644 --- a/src/rpc/utils/queueUtils.ts +++ b/src/rpc/utils/queueUtils.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/rpc/queue.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/rpc/queue.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/rpc/utils/sessionUtils.ts b/src/rpc/utils/sessionUtils.ts index 5b80b8a..8e9912e 100644 --- a/src/rpc/utils/sessionUtils.ts +++ b/src/rpc/utils/sessionUtils.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/rpc/session.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/rpc/session.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/rpc/utils/storageUtils.ts b/src/rpc/utils/storageUtils.ts index 3bef620..afd5284 100644 --- a/src/rpc/utils/storageUtils.ts +++ b/src/rpc/utils/storageUtils.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/rpc/storageUtils.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/rpc/storageUtils.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/service/BaseWebviewService.ts b/src/service/BaseWebviewService.ts index 770c523..66d89e0 100644 --- a/src/service/BaseWebviewService.ts +++ b/src/service/BaseWebviewService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/webview/BaseWebViewService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/webview/BaseWebViewService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/service/BricksDataService.ts b/src/service/BricksDataService.ts index 4c6b9c7..c943b26 100644 --- a/src/service/BricksDataService.ts +++ b/src/service/BricksDataService.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/service/BricksDataService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/service/BricksDataService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Tuesday, November 22nd 2022, 10:42:49 am * Author: ccagml * diff --git a/src/service/EventService.ts b/src/service/EventService.ts index edc33ee..d1ffe97 100644 --- a/src/service/EventService.ts +++ b/src/service/EventService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/EventService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/EventService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, November 10th 2022, 3:14:29 pm * Author: ccagml * diff --git a/src/service/ExecuteService.ts b/src/service/ExecuteService.ts index 8b53351..557e569 100644 --- a/src/service/ExecuteService.ts +++ b/src/service/ExecuteService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/executeService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/executeService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, October 31st 2022, 10:16:47 am * Author: ccagml * diff --git a/src/service/FileButtonService.ts b/src/service/FileButtonService.ts index 9c88ee0..57a3c9e 100644 --- a/src/service/FileButtonService.ts +++ b/src/service/FileButtonService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/FileButtonService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/FileButtonService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/service/MarkdownService.ts b/src/service/MarkdownService.ts index 26a0ea0..25574ed 100644 --- a/src/service/MarkdownService.ts +++ b/src/service/MarkdownService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/markdownService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/markdownService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/service/PreviewService.ts b/src/service/PreviewService.ts index 4787e0d..c826c2a 100644 --- a/src/service/PreviewService.ts +++ b/src/service/PreviewService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/previewService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/previewService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/service/SolutionService.ts b/src/service/SolutionService.ts index cbf3085..3af5c9d 100644 --- a/src/service/SolutionService.ts +++ b/src/service/SolutionService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/SolutionService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/SolutionService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/service/StatusBarService.ts b/src/service/StatusBarService.ts index fc0496d..7d25750 100644 --- a/src/service/StatusBarService.ts +++ b/src/service/StatusBarService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/StatusBarService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/StatusBarService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/service/StatusBarTimeService.ts b/src/service/StatusBarTimeService.ts index 0af55d7..8548b55 100644 --- a/src/service/StatusBarTimeService.ts +++ b/src/service/StatusBarTimeService.ts @@ -1,6 +1,6 @@ /* - * https://github.com/ccagml/leetcode-vscode/src/service/StatusBarTimeService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * https://github.com/ccagml/leetcode_extension/src/service/StatusBarTimeService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Saturday, November 26th 2022, 2:14:53 pm * Author: ccagml * diff --git a/src/service/SubmissionService.ts b/src/service/SubmissionService.ts index 11a65be..d255ab2 100644 --- a/src/service/SubmissionService.ts +++ b/src/service/SubmissionService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/SubmissionService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/SubmissionService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/service/TreeDataService.ts b/src/service/TreeDataService.ts index 718c6b7..248df59 100644 --- a/src/service/TreeDataService.ts +++ b/src/service/TreeDataService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/TreeDataService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/TreeDataService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/service/TreeItemDecorationService.ts b/src/service/TreeItemDecorationService.ts index b1a3329..dbe54a9 100644 --- a/src/service/TreeItemDecorationService.ts +++ b/src/service/TreeItemDecorationService.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/service/TreeItemDecorationService.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/service/TreeItemDecorationService.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/utils/CliUtils.ts b/src/utils/CliUtils.ts index d8bfd55..fac2ecc 100644 --- a/src/utils/CliUtils.ts +++ b/src/utils/CliUtils.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/utils/cliUtils.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/utils/cliUtils.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Monday, October 31st 2022, 10:16:47 am * Author: ccagml * diff --git a/src/utils/ConfigUtils.ts b/src/utils/ConfigUtils.ts index f6ca700..f89e565 100644 --- a/src/utils/ConfigUtils.ts +++ b/src/utils/ConfigUtils.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/utils/configUtils.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/utils/configUtils.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/utils/OutputUtils.ts b/src/utils/OutputUtils.ts index b32c2dc..fd70796 100644 --- a/src/utils/OutputUtils.ts +++ b/src/utils/OutputUtils.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/utils/OutputUtils.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/utils/OutputUtils.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * diff --git a/src/utils/SystemUtils.ts b/src/utils/SystemUtils.ts index dedc758..2d03718 100644 --- a/src/utils/SystemUtils.ts +++ b/src/utils/SystemUtils.ts @@ -1,6 +1,6 @@ /* - * Filename: https://github.com/ccagml/leetcode-vscode/src/utils/SystemUtils.ts - * Path: https://github.com/ccagml/leetcode-vscode + * Filename: https://github.com/ccagml/leetcode_extension/src/utils/SystemUtils.ts + * Path: https://github.com/ccagml/leetcode_extension * Created Date: Thursday, October 27th 2022, 7:43:29 pm * Author: ccagml * From 78e19ff21dc4579877592a684f8ab8119a04ac6e Mon Sep 17 00:00:00 2001 From: ccagml Date: Mon, 30 Jan 2023 00:05:23 +0800 Subject: [PATCH 06/11] =?UTF-8?q?US=E7=AB=99=E4=B8=80=E4=BA=9B=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 + package-lock.json | 4 +- package.json | 2 +- src/rpc/actionChain/chainNode/leetcode.ts | 110 ++++++++++++++++++++++ 4 files changed, 118 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05b8c1b..1308d1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## version 2.13.4 + +- US站一些报错 + + ## version 2.13.3 - 修改README.md diff --git a/package-lock.json b/package-lock.json index d0282a1..bc6f60f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-leetcode-problem-rating", - "version": "2.13.1", + "version": "2.13.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-leetcode-problem-rating", - "version": "2.13.1", + "version": "2.13.3", "license": "MIT", "dependencies": { "ansi-styles": "3.2.1", diff --git a/package.json b/package.json index ceaa212..50d9f71 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-leetcode-problem-rating", "displayName": "LeetCode", "description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了", - "version": "2.13.3", + "version": "2.13.4", "author": "ccagml", "publisher": "ccagml", "license": "MIT", diff --git a/src/rpc/actionChain/chainNode/leetcode.ts b/src/rpc/actionChain/chainNode/leetcode.ts index c83158f..4dd7ba3 100644 --- a/src/rpc/actionChain/chainNode/leetcode.ts +++ b/src/rpc/actionChain/chainNode/leetcode.ts @@ -672,6 +672,116 @@ and csrf token to the user object and saves the user object to the session. */ }); }); }; + + /* A function that is used to get the rating of the problems. */ + getRatingOnline = (cb) => { + const _request = request.defaults({ timeout: 2000, jar: true }); + _request("https://zerotrac.github.io/leetcode_problem_rating/data.json", function (error: any, _, body: any) { + // console.log(error); + // console.log(info); + cb(error, body); + }); + }; + + /* A function that gets the question of the day from leetcode. */ + getQuestionOfToday = (cb) => { + const opts = makeOpts(configUtils.sys.urls.graphql); + opts.headers.Origin = configUtils.sys.urls.base; + opts.headers.Referer = "https://leetcode.com/"; + + opts.json = true; + opts.body = { + operationName: "questionOfToday", + variables: {}, + query: [ + "query questionOfToday {", + " todayRecord {", + " date", + " userStatus", + " question {", + " titleSlug", + " questionId", + " questionFrontendId", + // ' content', + // ' stats', + // ' likes', + // ' dislikes', + // ' codeDefinition', + // ' sampleTestCase', + // ' enableRunCode', + // ' metaData', + // ' translatedContent', + " __typename", + " }", + " __typename", + " }", + "}", + ].join("\n"), + }; + + // request.post(opts, function (e, resp, body) { + // e = checkError(e, resp, 200); + // if (e) return cb(e); + // let result: any = {}; + // result.titleSlug = body.data.todayRecord[0].question.titleSlug; + // result.questionId = body.data.todayRecord[0].question.questionId; + // result.fid = body.data.todayRecord[0].question.questionFrontendId; + // result.date = body.data.todayRecord[0].data; + // result.userStatus = body.data.todayRecord[0].userStatus; + // return cb(null, result); + // }); + cb(null, {}) + }; + + /* A function that is used to get the user contest ranking information. */ + getUserContestP = (username, cb) => { + const opts = makeOpts(configUtils.sys.urls.noj_go); + opts.headers.Origin = configUtils.sys.urls.base; + opts.headers.Referer = configUtils.sys.urls.u.replace("$username", username); + + opts.json = true; + opts.body = { + variables: { + userSlug: username, + }, + query: [ + " query userContestRankingInfo($userSlug: String!) {", + " userContestRanking(userSlug: $userSlug) {", + " attendedContestsCount", + " rating", + " globalRanking", + " localRanking", + " globalTotalParticipants", + " localTotalParticipants", + " topPercentage", + " }", + // ' userContestRankingHistory(userSlug: $userSlug) {', + // ' attended', + // ' totalProblems', + // ' trendingDirection', + // ' finishTimeInSeconds', + // ' rating', + // ' score', + // ' ranking', + // ' contest {', + // ' title', + // ' titleCn', + // ' startTime', + // ' }', + // ' }', + " }", + ].join("\n"), + }; + + // request.post(opts, function (e, resp, body) { + // e = checkError(e, resp, 200); + // if (e) return cb(e); + + // return cb(null, body.data); + // }); + cb(null, {}) + }; + getHelpOnline = (problem, _, lang) => { getHelpEn(problem, lang, function (e, solution) { if (e) return; From f15583333e6419e9f700932833e749cda0dc0e08 Mon Sep 17 00:00:00 2001 From: ccagml Date: Mon, 30 Jan 2023 11:08:40 +0800 Subject: [PATCH 07/11] add nls --- CHANGELOG.md | 9 ++- nls.js | 131 +++++++++++++++++++++++++++++++++++++++++ nls.json | 98 ++++++++++++++++++++++++++++++ nls.ts | 88 +++++++++++++++++++++++++++ package.json | 4 +- package.nls.json | 98 ++++++++++++++++++++++++++++++ package.nls.zh-cn.json | 98 ++++++++++++++++++++++++++++++ 7 files changed, 521 insertions(+), 5 deletions(-) create mode 100644 nls.js create mode 100644 nls.json create mode 100644 nls.ts create mode 100644 package.nls.json create mode 100644 package.nls.zh-cn.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 1308d1c..841f721 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ -## version 2.13.4 +## version 2.14.1 + +- 尝试增加语言本地化 -- US站一些报错 +## version 2.13.4 +- US 站一些报错 ## version 2.13.3 -- 修改README.md +- 修改 README.md ## version 2.13.2 diff --git a/nls.js b/nls.js new file mode 100644 index 0000000..fdde78f --- /dev/null +++ b/nls.js @@ -0,0 +1,131 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var fse = require("fs-extra"); +var result_json = {}; +function check_key(object, father) { + var main_join = father.join("."); + if (object["description"]) { + var key = main_join + ".description"; + if (result_json[key]) { + console.log("重复", key, object); + } + result_json[key] = object["description"]; + } + if (object["title"]) { + var key = main_join + ".title"; + if (result_json[key]) { + console.log("重复", key); + } + result_json[key] = object["title"]; + } + if (object["name"]) { + var key = main_join + ".name"; + if (result_json[key]) { + console.log("重复", key); + } + result_json[key] = object["name"]; + } + if (object["label"]) { + var key = main_join + ".label"; + if (result_json[key]) { + console.log("重复", key); + } + result_json[key] = object["label"]; + } + if (object["enumDescriptions"]) { + var key = main_join + ".enumDescriptions"; + if (result_json[key]) { + console.log("重复", key); + } + result_json[key] = object["enumDescriptions"]; + } +} +function print_obj(object, father) { + var obj_key = object["command"] || object["id"]; + if (obj_key) { + father.push(obj_key); + } + check_key(object, father); + for (var key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + var element = object[key]; + father.push(key); + if (Array.isArray(element)) { + print_arr(element, father); + } + else if (typeof element == "object") { + print_obj(element, father); + } + father.pop(); + } + } + if (obj_key) { + father.pop(); + } +} +function print_arr(object, father) { + for (var i = 0; i < object.length; i++) { + var element = object[i]; + if (Array.isArray(element)) { + print_arr(element, father); + } + else if (typeof element == "object") { + print_obj(element, father); + } + } +} +function test() { + return __awaiter(this, void 0, void 0, function () { + var temp_data, ob; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, fse.readFile("./package.json", "utf8")]; + case 1: + temp_data = _a.sent(); + ob = JSON.parse(temp_data); + print_obj(ob, ["main"]); + return [4 /*yield*/, fse.writeFile("./nls.json", JSON.stringify(result_json))]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); +} +test(); diff --git a/nls.json b/nls.json new file mode 100644 index 0000000..1b23f11 --- /dev/null +++ b/nls.json @@ -0,0 +1,98 @@ +{ + "main.description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了", + "main.name": "vscode-leetcode-problem-rating", + "main.contributes.commands.lcpr.deleteCache.title": "Delete Cache", + "main.contributes.commands.lcpr.toggleLeetCodeCn.title": "Switch Endpoint", + "main.contributes.commands.lcpr.signin.title": "Sign In", + "main.contributes.commands.lcpr.signout.title": "Sign Out", + "main.contributes.commands.lcpr.refreshExplorer.title": "刷新", + "main.contributes.commands.lcpr.pickOne.title": "手气一下", + "main.contributes.commands.lcpr.deleteAllCache.title": "删除题目缓存", + "main.contributes.commands.lcpr.showProblem.title": "做题", + "main.contributes.commands.lcpr.previewProblem.title": "预览题目", + "main.contributes.commands.lcpr.setBricksType0.title": "设置不出现在工地", + "main.contributes.commands.lcpr.setBricksType1.title": "最后一次提交在14天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType2.title": "最后一次提交在7天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType3.title": "最后一次提交在5天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType4.title": "最后一次提交在3天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType5.title": "最后一次提交在2天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType6.title": "最后一次提交在1天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType7.title": "最后一次提交在1天前,出现在工地", + "main.contributes.commands.lcpr.searchProblem.title": "Search Problem", + "main.contributes.commands.lcpr.getHelp.title": "获取题解", + "main.contributes.commands.lcpr.testSolution.title": "Test in LeetCode", + "main.contributes.commands.lcpr.submitSolution.title": "Submit to LeetCode", + "main.contributes.commands.lcpr.addFavorite.title": "Add to Favorite List", + "main.contributes.commands.lcpr.removeFavorite.title": "Remove from Favorite List", + "main.contributes.commands.lcpr.setDefaultLanguage.title": "Switch Default Language", + "main.contributes.commands.lcpr.problems.sort.title": "Sort Problems", + "main.contributes.commands.lcpr.remarkCreateNote.title": "Create Note", + "main.contributes.commands.lcpr.remarkClose.title": "关闭?", + "main.contributes.commands.lcpr.remarkReplyNote.title": "New Note", + "main.contributes.commands.lcpr.remarkEditNote.title": "Edit Note", + "main.contributes.commands.lcpr.remarkDeleteNoteComment.title": "Delete Note", + "main.contributes.commands.lcpr.remarkSaveNote.title": "Save Note", + "main.contributes.commands.lcpr.remarkCancelsaveNote.title": "Cancel Note", + "main.contributes.commands.lcpr.remarkDispose.title": "Remove All Notes", + "main.contributes.commands.lcpr.newBrickGroup.title": "新建一个自定义分类", + "main.contributes.commands.lcpr.addQidToGroup.title": "添加题目到自定义分类", + "main.contributes.commands.lcpr.removeBrickGroup.title": "移除这个自定义分类", + "main.contributes.commands.lcpr.removeQidFromGroup.title": "从分类中移除这个题目", + "main.contributes.commands.lcpr.includeTemplates.title": "插入头文件模板", + "main.contributes.viewsContainers.activitybar.lcpr_bar.title": "LCPR", + "main.contributes.views.lcpr_bar.QuestionExplorer.name": "Problems", + "main.contributes.views.lcpr_bar.BricksExplorer.name": "搬砖工地", + "main.contributes.submenus.lcpr.editorAction.label": "LCPR菜单", + "main.contributes.submenus.lcpr.setBricksType_sub.label": "设置砖头类型", + "main.contributes.submenus.lcpr.setBricksType_sub1.label": "设置砖头类型", + "main.contributes.configuration.title": "leetcode-problem-rating", + "main.contributes.configuration.properties.leetcode-problem-rating.includeTemplates.description": "引入一些默认内容,防止vscode都是波浪红线", + "main.contributes.configuration.properties.leetcode-problem-rating.includeTemplates.items.properties.language.description": "哪种语言", + "main.contributes.configuration.properties.leetcode-problem-rating.includeTemplates.items.properties.template.description": "模板内容", + "main.contributes.configuration.properties.leetcode-problem-rating.hideSolved.description": "Hide solved problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.showLocked.description": "Show locked problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.defaultLanguage.description": "Default language for solving the problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.showDescription.description": "Specify where to show the description.", + "main.contributes.configuration.properties.leetcode-problem-rating.showDescription.enumDescriptions": [ + "Show the problem description in a new webview window", + "Show the problem description in the file's comment" + ], + "main.contributes.configuration.properties.leetcode-problem-rating.showCommentDescription.description": "[Deprecated] Include problem description in comments.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.setDefaultLanguage.description": "Show a hint to set the default language.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.configWebviewMarkdown.description": "Show a hint to change webview appearance through markdown config.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.commentDescription.description": "Show a hint to enable comment description in solution code file.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.commandShortcut.description": "Show a hint to configure commands key binding.", + "main.contributes.configuration.properties.leetcode-problem-rating.useVscodeNode.description": "Try the node version of vecode.", + "main.contributes.configuration.properties.leetcode-problem-rating.useWsl.description": "Use the Windows Subsystem for Linux.", + "main.contributes.configuration.properties.leetcode-problem-rating.endpoint.description": "Endpoint of the user account.", + "main.contributes.configuration.properties.leetcode-problem-rating.useEndpointTranslation.description": "Use endpoint's translation (if available)", + "main.contributes.configuration.properties.leetcode-problem-rating.answerDiffColor.description": "答案不同地方上色", + "main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description": "The path of the workspace folder to store the problem files.", + "main.contributes.configuration.properties.leetcode-problem-rating.filePath.description": "The output folder and filename to save the problem files.", + "main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "Show the LeetCode status bar or not.", + "main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.description": "Customize the shortcuts in editors.", + "main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions": [ + "Submit your answer to LeetCode.", + "Test your answer with customized test cases.", + "Star or unstar the current problem.", + "Show the top voted solution for the current problem.", + "Show the problem description page.", + "Test default case", + "Test all default case" + ], + "main.contributes.configuration.properties.leetcode-problem-rating.enableSideMode.description": "Determine whether to group all webview pages into the second editor column when solving problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.nodePath.description": "The Node.js executable path. for example, C:\\Program Files\\nodejs\\node.exe", + "main.contributes.configuration.properties.leetcode-problem-rating.colorizeProblems.description": "Add difficulty badge and colorize problems files in explorer tree.", + "main.contributes.configuration.properties.leetcode-problem-rating.problems.sortStrategy.description": "Sorting strategy for problems list.", + "main.contributes.configuration.properties.leetcode-problem-rating.pickOneByRankRangeMin.description": "Minimum score for a random question(your score + pickOneByRankRangeMin) ", + "main.contributes.configuration.properties.leetcode-problem-rating.pickOneByRankRangeMax.description": "Highest score for a random question(your score + pickOneByRankRangeMax)", + "main.contributes.configuration.properties.leetcode-problem-rating.hideScore.description": "Precinct Score Hidden Questions.", + "main.contributes.configuration.properties.leetcode-problem-rating.hideScore.enumDescriptions": [ + "Don't hide", + "Hide questions with scores", + "Hide questions with no scores", + "Hide questions outside the range of scores [pickOneByRankRangeMin, pickOneByRankRangeMax]" + ], + "main.contributes.configuration.properties.leetcode-problem-rating.openClearProblemCache.description": "Clear the Problems cache when opening the app to avoid out-of-sync state", + "main.contributes.configuration.properties.leetcode-problem-rating.openClearProblemCacheTime.description": "Open the app to clear the cache interval by default 3600 seconds" +} diff --git a/nls.ts b/nls.ts new file mode 100644 index 0000000..b7c1343 --- /dev/null +++ b/nls.ts @@ -0,0 +1,88 @@ +import * as fse from "fs-extra"; + +let result_json = {}; + +function check_key(object, father: Array) { + let main_join = father.join("."); + + if (object["description"]) { + let key = main_join + ".description"; + + if (result_json[key]) { + console.log("重复", key, object); + } + + result_json[key] = object["description"]; + } + if (object["title"]) { + let key = main_join + ".title"; + if (result_json[key]) { + console.log("重复", key); + } + result_json[key] = object["title"]; + } + if (object["name"]) { + let key = main_join + ".name"; + if (result_json[key]) { + console.log("重复", key); + } + result_json[key] = object["name"]; + } + if (object["label"]) { + let key = main_join + ".label"; + if (result_json[key]) { + console.log("重复", key); + } + result_json[key] = object["label"]; + } + if (object["enumDescriptions"]) { + let key = main_join + ".enumDescriptions"; + if (result_json[key]) { + console.log("重复", key); + } + result_json[key] = object["enumDescriptions"]; + } +} + +function print_obj(object, father) { + let obj_key = object["command"] || object["id"]; + if (obj_key) { + father.push(obj_key); + } + check_key(object, father); + for (const key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + const element = object[key]; + father.push(key); + if (Array.isArray(element)) { + print_arr(element, father); + } else if (typeof element == "object") { + print_obj(element, father); + } + father.pop(); + } + } + if (obj_key) { + father.pop(); + } +} +function print_arr(object, father) { + for (let i = 0; i < object.length; i++) { + const element = object[i]; + + if (Array.isArray(element)) { + print_arr(element, father); + } else if (typeof element == "object") { + print_obj(element, father); + } + } +} + +async function test() { + let temp_data = await fse.readFile("./package.json", "utf8"); + let ob = JSON.parse(temp_data); + print_obj(ob, ["main"]); + await fse.writeFile("./nls.json", JSON.stringify(result_json)); +} + +test(); diff --git a/package.json b/package.json index 50d9f71..efec44e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "vscode-leetcode-problem-rating", "displayName": "LeetCode", - "description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了", - "version": "2.13.4", + "description": "%main.description%", + "version": "2.14.1", "author": "ccagml", "publisher": "ccagml", "license": "MIT", diff --git a/package.nls.json b/package.nls.json new file mode 100644 index 0000000..06fda06 --- /dev/null +++ b/package.nls.json @@ -0,0 +1,98 @@ +{ + "main.description": "LeetCode official plug-in enhancement, code open source, increase the difficulty score of LeetCode questions, give a star, please~", + "main.name": "vscode-leetcode-problem-rating", + "main.contributes.commands.lcpr.deleteCache.title": "Delete Cache", + "main.contributes.commands.lcpr.toggleLeetCodeCn.title": "Switch Endpoint", + "main.contributes.commands.lcpr.signin.title": "Sign In", + "main.contributes.commands.lcpr.signout.title": "Sign Out", + "main.contributes.commands.lcpr.refreshExplorer.title": "刷新", + "main.contributes.commands.lcpr.pickOne.title": "手气一下", + "main.contributes.commands.lcpr.deleteAllCache.title": "删除题目缓存", + "main.contributes.commands.lcpr.showProblem.title": "做题", + "main.contributes.commands.lcpr.previewProblem.title": "预览题目", + "main.contributes.commands.lcpr.setBricksType0.title": "设置不出现在工地", + "main.contributes.commands.lcpr.setBricksType1.title": "setBricksType1setBricksType1setBricksType1", + "main.contributes.commands.lcpr.setBricksType2.title": "setBricksType2setBricksType2setBricksType2,出现在工地", + "main.contributes.commands.lcpr.setBricksType3.title": "最后一次提交在5天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType4.title": "最后一次提交在3天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType5.title": "最后一次提交在2天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType6.title": "最后一次提交在1天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType7.title": "最后一次提交在1天前,出现在工地", + "main.contributes.commands.lcpr.searchProblem.title": "Search Problem", + "main.contributes.commands.lcpr.getHelp.title": "获取题解", + "main.contributes.commands.lcpr.testSolution.title": "Test in LeetCode", + "main.contributes.commands.lcpr.submitSolution.title": "Submit to LeetCode", + "main.contributes.commands.lcpr.addFavorite.title": "Add to Favorite List", + "main.contributes.commands.lcpr.removeFavorite.title": "Remove from Favorite List", + "main.contributes.commands.lcpr.setDefaultLanguage.title": "Switch Default Language", + "main.contributes.commands.lcpr.problems.sort.title": "Sort Problems", + "main.contributes.commands.lcpr.remarkCreateNote.title": "Create Note", + "main.contributes.commands.lcpr.remarkClose.title": "关闭?", + "main.contributes.commands.lcpr.remarkReplyNote.title": "New Note", + "main.contributes.commands.lcpr.remarkEditNote.title": "Edit Note", + "main.contributes.commands.lcpr.remarkDeleteNoteComment.title": "Delete Note", + "main.contributes.commands.lcpr.remarkSaveNote.title": "Save Note", + "main.contributes.commands.lcpr.remarkCancelsaveNote.title": "Cancel Note", + "main.contributes.commands.lcpr.remarkDispose.title": "Remove All Notes", + "main.contributes.commands.lcpr.newBrickGroup.title": "新建一个自定义分类", + "main.contributes.commands.lcpr.addQidToGroup.title": "添加题目到自定义分类", + "main.contributes.commands.lcpr.removeBrickGroup.title": "移除这个自定义分类", + "main.contributes.commands.lcpr.removeQidFromGroup.title": "从分类中移除这个题目", + "main.contributes.commands.lcpr.includeTemplates.title": "插入头文件模板", + "main.contributes.viewsContainers.activitybar.lcpr_bar.title": "LCPR", + "main.contributes.views.lcpr_bar.QuestionExplorer.name": "Problems", + "main.contributes.views.lcpr_bar.BricksExplorer.name": "搬砖工地", + "main.contributes.submenus.lcpr.editorAction.label": "LCPR菜单", + "main.contributes.submenus.lcpr.setBricksType_sub.label": "设置砖头类型", + "main.contributes.submenus.lcpr.setBricksType_sub1.label": "设置砖头类型", + "main.contributes.configuration.title": "leetcode-problem-rating", + "main.contributes.configuration.properties.leetcode-problem-rating.includeTemplates.description": "引入一些默认内容,防止vscode都是波浪红线", + "main.contributes.configuration.properties.leetcode-problem-rating.includeTemplates.items.properties.language.description": "哪种语言", + "main.contributes.configuration.properties.leetcode-problem-rating.includeTemplates.items.properties.template.description": "模板内容", + "main.contributes.configuration.properties.leetcode-problem-rating.hideSolved.description": "Hide solved problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.showLocked.description": "Show locked problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.defaultLanguage.description": "Default language for solving the problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.showDescription.description": "Specify where to show the description.", + "main.contributes.configuration.properties.leetcode-problem-rating.showDescription.enumDescriptions": [ + "Show the problem description in a new webview window", + "Show the problem description in the file's comment" + ], + "main.contributes.configuration.properties.leetcode-problem-rating.showCommentDescription.description": "[Deprecated] Include problem description in comments.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.setDefaultLanguage.description": "Show a hint to set the default language.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.configWebviewMarkdown.description": "Show a hint to change webview appearance through markdown config.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.commentDescription.description": "Show a hint to enable comment description in solution code file.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.commandShortcut.description": "Show a hint to configure commands key binding.", + "main.contributes.configuration.properties.leetcode-problem-rating.useVscodeNode.description": "Try the node version of vecode.", + "main.contributes.configuration.properties.leetcode-problem-rating.useWsl.description": "Use the Windows Subsystem for Linux.", + "main.contributes.configuration.properties.leetcode-problem-rating.endpoint.description": "Endpoint of the user account.", + "main.contributes.configuration.properties.leetcode-problem-rating.useEndpointTranslation.description": "Use endpoint's translation (if available)", + "main.contributes.configuration.properties.leetcode-problem-rating.answerDiffColor.description": "答案不同地方上色", + "main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description": "The path of the workspace folder to store the problem files.", + "main.contributes.configuration.properties.leetcode-problem-rating.filePath.description": "The output folder and filename to save the problem files.", + "main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "Show the LeetCode status bar or not.", + "main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.description": "Customize the shortcuts in editors.", + "main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions": [ + "Submit your answer to LeetCode.", + "Test your answer with customized test cases.", + "Star or unstar the current problem.", + "Show the top voted solution for the current problem.", + "Show the problem description page.", + "Test default case", + "Test all default case" + ], + "main.contributes.configuration.properties.leetcode-problem-rating.enableSideMode.description": "Determine whether to group all webview pages into the second editor column when solving problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.nodePath.description": "The Node.js executable path. for example, C:\\Program Files\\nodejs\\node.exe", + "main.contributes.configuration.properties.leetcode-problem-rating.colorizeProblems.description": "Add difficulty badge and colorize problems files in explorer tree.", + "main.contributes.configuration.properties.leetcode-problem-rating.problems.sortStrategy.description": "Sorting strategy for problems list.", + "main.contributes.configuration.properties.leetcode-problem-rating.pickOneByRankRangeMin.description": "Minimum score for a random question(your score + pickOneByRankRangeMin) ", + "main.contributes.configuration.properties.leetcode-problem-rating.pickOneByRankRangeMax.description": "Highest score for a random question(your score + pickOneByRankRangeMax)", + "main.contributes.configuration.properties.leetcode-problem-rating.hideScore.description": "Precinct Score Hidden Questions.", + "main.contributes.configuration.properties.leetcode-problem-rating.hideScore.enumDescriptions": [ + "Don't hide", + "Hide questions with scores", + "Hide questions with no scores", + "Hide questions outside the range of scores [pickOneByRankRangeMin, pickOneByRankRangeMax]" + ], + "main.contributes.configuration.properties.leetcode-problem-rating.openClearProblemCache.description": "Clear the Problems cache when opening the app to avoid out-of-sync state", + "main.contributes.configuration.properties.leetcode-problem-rating.openClearProblemCacheTime.description": "Open the app to clear the cache interval by default 3600 seconds" +} diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json new file mode 100644 index 0000000..d2455b0 --- /dev/null +++ b/package.nls.zh-cn.json @@ -0,0 +1,98 @@ +{ + "main.description": "LeetCode 官方插件增强, 代码开源, 增加 LeetCode 题目难度分, 给个star吧, 球球了~", + "main.name": "vscode-leetcode-problem-rating", + "main.contributes.commands.lcpr.deleteCache.title": "Delete Cache", + "main.contributes.commands.lcpr.toggleLeetCodeCn.title": "Switch Endpoint", + "main.contributes.commands.lcpr.signin.title": "Sign In", + "main.contributes.commands.lcpr.signout.title": "Sign Out", + "main.contributes.commands.lcpr.refreshExplorer.title": "刷新", + "main.contributes.commands.lcpr.pickOne.title": "手气一下", + "main.contributes.commands.lcpr.deleteAllCache.title": "删除题目缓存", + "main.contributes.commands.lcpr.showProblem.title": "做题", + "main.contributes.commands.lcpr.previewProblem.title": "预览题目", + "main.contributes.commands.lcpr.setBricksType0.title": "设置不出现在工地", + "main.contributes.commands.lcpr.setBricksType1.title": "最后一次提交在14天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType2.title": "最后一次提交在7天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType3.title": "最后一次提交在5天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType4.title": "最后一次提交在3天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType5.title": "最后一次提交在2天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType6.title": "最后一次提交在1天前,出现在工地", + "main.contributes.commands.lcpr.setBricksType7.title": "最后一次提交在1天前,出现在工地", + "main.contributes.commands.lcpr.searchProblem.title": "Search Problem", + "main.contributes.commands.lcpr.getHelp.title": "获取题解", + "main.contributes.commands.lcpr.testSolution.title": "Test in LeetCode", + "main.contributes.commands.lcpr.submitSolution.title": "Submit to LeetCode", + "main.contributes.commands.lcpr.addFavorite.title": "Add to Favorite List", + "main.contributes.commands.lcpr.removeFavorite.title": "Remove from Favorite List", + "main.contributes.commands.lcpr.setDefaultLanguage.title": "Switch Default Language", + "main.contributes.commands.lcpr.problems.sort.title": "Sort Problems", + "main.contributes.commands.lcpr.remarkCreateNote.title": "Create Note", + "main.contributes.commands.lcpr.remarkClose.title": "关闭?", + "main.contributes.commands.lcpr.remarkReplyNote.title": "New Note", + "main.contributes.commands.lcpr.remarkEditNote.title": "Edit Note", + "main.contributes.commands.lcpr.remarkDeleteNoteComment.title": "Delete Note", + "main.contributes.commands.lcpr.remarkSaveNote.title": "Save Note", + "main.contributes.commands.lcpr.remarkCancelsaveNote.title": "Cancel Note", + "main.contributes.commands.lcpr.remarkDispose.title": "Remove All Notes", + "main.contributes.commands.lcpr.newBrickGroup.title": "新建一个自定义分类", + "main.contributes.commands.lcpr.addQidToGroup.title": "添加题目到自定义分类", + "main.contributes.commands.lcpr.removeBrickGroup.title": "移除这个自定义分类", + "main.contributes.commands.lcpr.removeQidFromGroup.title": "从分类中移除这个题目", + "main.contributes.commands.lcpr.includeTemplates.title": "插入头文件模板", + "main.contributes.viewsContainers.activitybar.lcpr_bar.title": "LCPR", + "main.contributes.views.lcpr_bar.QuestionExplorer.name": "Problems", + "main.contributes.views.lcpr_bar.BricksExplorer.name": "搬砖工地", + "main.contributes.submenus.lcpr.editorAction.label": "LCPR菜单", + "main.contributes.submenus.lcpr.setBricksType_sub.label": "设置砖头类型", + "main.contributes.submenus.lcpr.setBricksType_sub1.label": "设置砖头类型", + "main.contributes.configuration.title": "leetcode-problem-rating", + "main.contributes.configuration.properties.leetcode-problem-rating.includeTemplates.description": "引入一些默认内容,防止vscode都是波浪红线", + "main.contributes.configuration.properties.leetcode-problem-rating.includeTemplates.items.properties.language.description": "哪种语言", + "main.contributes.configuration.properties.leetcode-problem-rating.includeTemplates.items.properties.template.description": "模板内容", + "main.contributes.configuration.properties.leetcode-problem-rating.hideSolved.description": "Hide solved problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.showLocked.description": "Show locked problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.defaultLanguage.description": "Default language for solving the problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.showDescription.description": "Specify where to show the description.", + "main.contributes.configuration.properties.leetcode-problem-rating.showDescription.enumDescriptions": [ + "Show the problem description in a new webview window", + "Show the problem description in the file's comment" + ], + "main.contributes.configuration.properties.leetcode-problem-rating.showCommentDescription.description": "[Deprecated] Include problem description in comments.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.setDefaultLanguage.description": "Show a hint to set the default language.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.configWebviewMarkdown.description": "Show a hint to change webview appearance through markdown config.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.commentDescription.description": "Show a hint to enable comment description in solution code file.", + "main.contributes.configuration.properties.leetcode-problem-rating.hint.commandShortcut.description": "Show a hint to configure commands key binding.", + "main.contributes.configuration.properties.leetcode-problem-rating.useVscodeNode.description": "Try the node version of vecode.", + "main.contributes.configuration.properties.leetcode-problem-rating.useWsl.description": "Use the Windows Subsystem for Linux.", + "main.contributes.configuration.properties.leetcode-problem-rating.endpoint.description": "Endpoint of the user account.", + "main.contributes.configuration.properties.leetcode-problem-rating.useEndpointTranslation.description": "Use endpoint's translation (if available)", + "main.contributes.configuration.properties.leetcode-problem-rating.answerDiffColor.description": "答案不同地方上色", + "main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description": "The path of the workspace folder to store the problem files.", + "main.contributes.configuration.properties.leetcode-problem-rating.filePath.description": "The output folder and filename to save the problem files.", + "main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "Show the LeetCode status bar or not.", + "main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.description": "Customize the shortcuts in editors.", + "main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions": [ + "Submit your answer to LeetCode.", + "Test your answer with customized test cases.", + "Star or unstar the current problem.", + "Show the top voted solution for the current problem.", + "Show the problem description page.", + "Test default case", + "Test all default case" + ], + "main.contributes.configuration.properties.leetcode-problem-rating.enableSideMode.description": "Determine whether to group all webview pages into the second editor column when solving problems.", + "main.contributes.configuration.properties.leetcode-problem-rating.nodePath.description": "The Node.js executable path. for example, C:\\Program Files\\nodejs\\node.exe", + "main.contributes.configuration.properties.leetcode-problem-rating.colorizeProblems.description": "Add difficulty badge and colorize problems files in explorer tree.", + "main.contributes.configuration.properties.leetcode-problem-rating.problems.sortStrategy.description": "Sorting strategy for problems list.", + "main.contributes.configuration.properties.leetcode-problem-rating.pickOneByRankRangeMin.description": "Minimum score for a random question(your score + pickOneByRankRangeMin) ", + "main.contributes.configuration.properties.leetcode-problem-rating.pickOneByRankRangeMax.description": "Highest score for a random question(your score + pickOneByRankRangeMax)", + "main.contributes.configuration.properties.leetcode-problem-rating.hideScore.description": "Precinct Score Hidden Questions.", + "main.contributes.configuration.properties.leetcode-problem-rating.hideScore.enumDescriptions": [ + "Don't hide", + "Hide questions with scores", + "Hide questions with no scores", + "Hide questions outside the range of scores [pickOneByRankRangeMin, pickOneByRankRangeMax]" + ], + "main.contributes.configuration.properties.leetcode-problem-rating.openClearProblemCache.description": "Clear the Problems cache when opening the app to avoid out-of-sync state", + "main.contributes.configuration.properties.leetcode-problem-rating.openClearProblemCacheTime.description": "Open the app to clear the cache interval by default 3600 seconds" +} From a5621ffc80dbece3a703da11893d25872e3588ba Mon Sep 17 00:00:00 2001 From: ccagml Date: Wed, 1 Feb 2023 10:01:57 +0800 Subject: [PATCH 08/11] =?UTF-8?q?BWC96=20&=20WC328=20&=20WC329=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 + package.json | 2 +- resources/data.json | 132 +++++++++++++++++++++++++++++++++ src/service/SolutionService.ts | 2 + 4 files changed, 139 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 841f721..65bd873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## version 2.14.2 + +- BWC96 & WC328 & WC329 数据 + ## version 2.14.1 - 尝试增加语言本地化 diff --git a/package.json b/package.json index efec44e..f9648ed 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-leetcode-problem-rating", "displayName": "LeetCode", "description": "%main.description%", - "version": "2.14.1", + "version": "2.14.2", "author": "ccagml", "publisher": "ccagml", "license": "MIT", diff --git a/resources/data.json b/resources/data.json index 67c3aa2..c8cecbf 100644 --- a/resources/data.json +++ b/resources/data.json @@ -868,6 +868,17 @@ "ContestID_en": "Weekly Contest 105", "ContestID_zh": "第 105 场周赛" }, + { + "Rating": 2397.9722495587, + "ID": 2538, + "Title": "Difference Between Maximum and Minimum Price Sum", + "TitleZH": "最大价值和与最小价值和的差值", + "TitleSlug": "difference-between-maximum-and-minimum-price-sum", + "ContestSlug": "weekly-contest-328", + "ProblemIndex": "Q4", + "ContestID_en": "Weekly Contest 328", + "ContestID_zh": "第 328 场周赛" + }, { "Rating": 2396.6267778669, "ID": 808, @@ -1792,6 +1803,17 @@ "ContestID_en": "Weekly Contest 211", "ContestID_zh": "第 211 场周赛" }, + { + "Rating": 2220.8257124139, + "ID": 2543, + "Title": "Check if Point Is Reachable", + "TitleZH": "判断一个点是否可以到达", + "TitleSlug": "check-if-point-is-reachable", + "ContestSlug": "biweekly-contest-96", + "ProblemIndex": "Q4", + "ContestID_en": "Biweekly Contest 96", + "ContestID_zh": "第 96 场双周赛" + }, { "Rating": 2220.0903365738, "ID": 2223, @@ -3057,6 +3079,17 @@ "ContestID_en": "Weekly Contest 192", "ContestID_zh": "第 192 场周赛" }, + { + "Rating": 2056.2598215101, + "ID": 2542, + "Title": "Maximum Subsequence Score", + "TitleZH": "最大子序列的分数", + "TitleSlug": "maximum-subsequence-score", + "ContestSlug": "biweekly-contest-96", + "ProblemIndex": "Q3", + "ContestID_en": "Biweekly Contest 96", + "ContestID_zh": "第 96 场双周赛" + }, { "Rating": 2055.0970201875, "ID": 1575, @@ -3442,6 +3475,17 @@ "ContestID_en": "Weekly Contest 325", "ContestID_zh": "第 325 场周赛" }, + { + "Rating": 2019.9859462755, + "ID": 2547, + "Title": "Minimum Cost to Split an Array", + "TitleZH": "拆分数组的最小代价", + "TitleSlug": "minimum-cost-to-split-an-array", + "ContestSlug": "weekly-contest-329", + "ProblemIndex": "Q4", + "ContestID_en": "Weekly Contest 329", + "ContestID_zh": "第 329 场周赛" + }, { "Rating": 2019.5399647546, "ID": 909, @@ -4652,6 +4696,17 @@ "ContestID_en": "Weekly Contest 223", "ContestID_zh": "第 223 场周赛" }, + { + "Rating": 1891.8455273506, + "ID": 2537, + "Title": "Count the Number of Good Subarrays", + "TitleZH": "统计好子数组的数目", + "TitleSlug": "count-the-number-of-good-subarrays", + "ContestSlug": "weekly-contest-328", + "ProblemIndex": "Q3", + "ContestID_en": "Weekly Contest 328", + "ContestID_zh": "第 328 场周赛" + }, { "Rating": 1886.7040111218, "ID": 2305, @@ -8106,6 +8161,17 @@ "ContestID_en": "Biweekly Contest 84", "ContestID_zh": "第 84 场双周赛" }, + { + "Rating": 1619.505461912, + "ID": 2541, + "Title": "Minimum Operations to Make Array Equal II", + "TitleZH": "使数组中所有元素相等的最小操作数 II", + "TitleSlug": "minimum-operations-to-make-array-equal-ii", + "ContestSlug": "biweekly-contest-96", + "ProblemIndex": "Q2", + "ContestID_en": "Biweekly Contest 96", + "ContestID_zh": "第 96 场双周赛" + }, { "Rating": 1618.6016480451, "ID": 1503, @@ -8282,6 +8348,17 @@ "ContestID_en": "Weekly Contest 78", "ContestID_zh": "第 78 场周赛" }, + { + "Rating": 1604.6299874552, + "ID": 2546, + "Title": "Apply Bitwise Operations to Make Strings Equal", + "TitleZH": "执行逐位运算使字符串相等", + "TitleSlug": "apply-bitwise-operations-to-make-strings-equal", + "ContestSlug": "weekly-contest-329", + "ProblemIndex": "Q3", + "ContestID_en": "Weekly Contest 329", + "ContestID_zh": "第 329 场周赛" + }, { "Rating": 1604.5128423093, "ID": 2522, @@ -8535,6 +8612,17 @@ "ContestID_en": "Weekly Contest 133", "ContestID_zh": "第 133 场周赛" }, + { + "Rating": 1583.3117784523, + "ID": 2536, + "Title": "Increment Submatrices by One", + "TitleZH": "子矩阵元素加 1", + "TitleSlug": "increment-submatrices-by-one", + "ContestSlug": "weekly-contest-328", + "ProblemIndex": "Q2", + "ContestID_en": "Weekly Contest 328", + "ContestID_zh": "第 328 场周赛" + }, { "Rating": 1581.4963716166, "ID": 2211, @@ -13188,6 +13276,17 @@ "ContestID_en": "Biweekly Contest 43", "ContestID_zh": "第 43 场双周赛" }, + { + "Rating": 1294.0257382852, + "ID": 2545, + "Title": "Sort the Students by Their Kth Score", + "TitleZH": "根据第 K 场考试的分数排序", + "TitleSlug": "sort-the-students-by-their-kth-score", + "ContestSlug": "weekly-contest-329", + "ProblemIndex": "Q2", + "ContestID_en": "Weekly Contest 329", + "ContestID_zh": "第 329 场周赛" + }, { "Rating": 1293.4904281819, "ID": 1551, @@ -14156,6 +14255,17 @@ "ContestID_en": "Biweekly Contest 86", "ContestID_zh": "第 86 场双周赛" }, + { + "Rating": 1249.7515196656, + "ID": 2540, + "Title": "Minimum Common Value", + "TitleZH": "最小公共值", + "TitleSlug": "minimum-common-value", + "ContestSlug": "biweekly-contest-96", + "ProblemIndex": "Q1", + "ContestID_en": "Biweekly Contest 96", + "ContestID_zh": "第 96 场双周赛" + }, { "Rating": 1249.4294341104, "ID": 766, @@ -14695,6 +14805,17 @@ "ContestID_en": "Weekly Contest 184", "ContestID_zh": "第 184 场周赛" }, + { + "Rating": 1222.2354919459, + "ID": 2535, + "Title": "Difference Between Element Sum and Digit Sum of an Array", + "TitleZH": "数组元素和与数字和的绝对差", + "TitleSlug": "difference-between-element-sum-and-digit-sum-of-an-array", + "ContestSlug": "weekly-contest-328", + "ProblemIndex": "Q1", + "ContestID_en": "Weekly Contest 328", + "ContestID_zh": "第 328 场周赛" + }, { "Rating": 1221.9872943569, "ID": 1678, @@ -15267,6 +15388,17 @@ "ContestID_en": "Weekly Contest 255", "ContestID_zh": "第 255 场周赛" }, + { + "Rating": 1184.3385083575, + "ID": 2544, + "Title": "Alternating Digit Sum", + "TitleZH": "交替数字和", + "TitleSlug": "alternating-digit-sum", + "ContestSlug": "weekly-contest-329", + "ProblemIndex": "Q1", + "ContestID_en": "Weekly Contest 329", + "ContestID_zh": "第 329 场周赛" + }, { "Rating": 1182.6489068544, "ID": 1672, diff --git a/src/service/SolutionService.ts b/src/service/SolutionService.ts index 3af5c9d..fbc16a8 100644 --- a/src/service/SolutionService.ts +++ b/src/service/SolutionService.ts @@ -57,6 +57,8 @@ class SolutionService extends BaseWebViewService { // $\textit this.solution.body = this.solution.body.replace(/\$\textit/g, "$"); + this.solution.body = this.solution.body.replace(/\$\texttt/g, "$"); + this.solution.body = this.solution.body.replace(/\$\text/g, "$"); const body: string = markdownService.render(this.solution.body, { lang: this.solution.lang, From 24443e36f57333d7f247462b3dc9586be559f702 Mon Sep 17 00:00:00 2001 From: ccagml Date: Sat, 4 Feb 2023 16:04:12 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E6=9A=82=E4=BB=A3debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 202 +- package.json | 5 + src/controller/DebugController.ts | 62 + src/controller/MainController.ts | 7 + src/controller/TreeViewController.ts | 70 +- src/debug/debugExecutor.ts | 187 + src/debug/entry/cpp/entry.cpp | 40 + src/debug/entry/cpp/problems/116.cpp | 46 + src/debug/entry/cpp/problems/116.h | 17 + src/debug/entry/cpp/problems/133.cpp | 19 + src/debug/entry/cpp/problems/133.h | 16 + src/debug/entry/cpp/problems/138.cpp | 45 + src/debug/entry/cpp/problems/138.h | 16 + src/debug/entry/cpp/problems/278.cpp | 10 + src/debug/entry/cpp/problems/278.h | 2 + src/debug/entry/cpp/problems/429.cpp | 47 + src/debug/entry/cpp/problems/429.h | 21 + src/debug/entry/cpp/problems/843.cpp | 18 + src/debug/entry/cpp/problems/843.h | 7 + src/debug/entry/cpp/problems/common.cpp | 292 + src/debug/entry/cpp/problems/common.h | 81 + src/debug/entry/javascript/entry.js | 371 ++ src/debug/entry/javascript/problems/1095.js | 11 + src/debug/entry/javascript/problems/116.js | 45 + src/debug/entry/javascript/problems/117.js | 52 + src/debug/entry/javascript/problems/133.js | 40 + src/debug/entry/javascript/problems/138.js | 44 + src/debug/entry/javascript/problems/278.js | 19 + src/debug/entry/javascript/problems/341.js | 18 + src/debug/entry/javascript/problems/429.js | 46 + src/debug/entry/javascript/problems/559.js | 46 + src/debug/entry/javascript/problems/589.js | 46 + src/debug/entry/javascript/problems/590.js | 46 + src/debug/entry/javascript/problems/843.js | 25 + src/debug/entry/javascript/problems/common.js | 16 + src/debug/entry/python3/entry.py | 336 ++ src/debug/entry/python3/problems/1095.py | 10 + src/debug/entry/python3/problems/116.py | 37 + src/debug/entry/python3/problems/117.py | 46 + src/debug/entry/python3/problems/133.py | 32 + src/debug/entry/python3/problems/138.py | 36 + src/debug/entry/python3/problems/278.py | 18 + src/debug/entry/python3/problems/429.py | 45 + src/debug/entry/python3/problems/559.py | 45 + src/debug/entry/python3/problems/589.py | 45 + src/debug/entry/python3/problems/590.py | 45 + src/debug/entry/python3/problems/843.py | 29 + src/debug/entry/python3/problems/common.py | 12 + src/debug/executor/cppExecutor.ts | 445 ++ src/debug/thirdparty/c/cJSON.c | 2979 +++++++++ src/debug/thirdparty/c/cJSON.h | 293 + src/extension.ts | 4 +- src/service/DebugService.ts | 155 + src/service/FileButtonService.ts | 28 +- src/utils/SystemUtils.ts | 47 + src/utils/problemTypes.ts | 5318 +++++++++++++++++ src/utils/problemUtils.ts | 201 + 57 files changed, 12078 insertions(+), 163 deletions(-) create mode 100644 src/controller/DebugController.ts create mode 100644 src/debug/debugExecutor.ts create mode 100644 src/debug/entry/cpp/entry.cpp create mode 100644 src/debug/entry/cpp/problems/116.cpp create mode 100644 src/debug/entry/cpp/problems/116.h create mode 100644 src/debug/entry/cpp/problems/133.cpp create mode 100644 src/debug/entry/cpp/problems/133.h create mode 100644 src/debug/entry/cpp/problems/138.cpp create mode 100644 src/debug/entry/cpp/problems/138.h create mode 100644 src/debug/entry/cpp/problems/278.cpp create mode 100644 src/debug/entry/cpp/problems/278.h create mode 100644 src/debug/entry/cpp/problems/429.cpp create mode 100644 src/debug/entry/cpp/problems/429.h create mode 100644 src/debug/entry/cpp/problems/843.cpp create mode 100644 src/debug/entry/cpp/problems/843.h create mode 100644 src/debug/entry/cpp/problems/common.cpp create mode 100644 src/debug/entry/cpp/problems/common.h create mode 100644 src/debug/entry/javascript/entry.js create mode 100644 src/debug/entry/javascript/problems/1095.js create mode 100644 src/debug/entry/javascript/problems/116.js create mode 100644 src/debug/entry/javascript/problems/117.js create mode 100644 src/debug/entry/javascript/problems/133.js create mode 100644 src/debug/entry/javascript/problems/138.js create mode 100644 src/debug/entry/javascript/problems/278.js create mode 100644 src/debug/entry/javascript/problems/341.js create mode 100644 src/debug/entry/javascript/problems/429.js create mode 100644 src/debug/entry/javascript/problems/559.js create mode 100644 src/debug/entry/javascript/problems/589.js create mode 100644 src/debug/entry/javascript/problems/590.js create mode 100644 src/debug/entry/javascript/problems/843.js create mode 100644 src/debug/entry/javascript/problems/common.js create mode 100644 src/debug/entry/python3/entry.py create mode 100644 src/debug/entry/python3/problems/1095.py create mode 100644 src/debug/entry/python3/problems/116.py create mode 100644 src/debug/entry/python3/problems/117.py create mode 100644 src/debug/entry/python3/problems/133.py create mode 100644 src/debug/entry/python3/problems/138.py create mode 100644 src/debug/entry/python3/problems/278.py create mode 100644 src/debug/entry/python3/problems/429.py create mode 100644 src/debug/entry/python3/problems/559.py create mode 100644 src/debug/entry/python3/problems/589.py create mode 100644 src/debug/entry/python3/problems/590.py create mode 100644 src/debug/entry/python3/problems/843.py create mode 100644 src/debug/entry/python3/problems/common.py create mode 100644 src/debug/executor/cppExecutor.ts create mode 100644 src/debug/thirdparty/c/cJSON.c create mode 100644 src/debug/thirdparty/c/cJSON.h create mode 100644 src/service/DebugService.ts create mode 100644 src/utils/problemTypes.ts create mode 100644 src/utils/problemUtils.ts diff --git a/package-lock.json b/package-lock.json index bc6f60f..7147e8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-leetcode-problem-rating", - "version": "2.13.3", + "version": "2.14.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-leetcode-problem-rating", - "version": "2.13.3", + "version": "2.14.2", "license": "MIT", "dependencies": { "ansi-styles": "3.2.1", @@ -276,15 +276,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.49.0.tgz", - "integrity": "sha512-IhxabIpcf++TBaBa1h7jtOWyon80SXPRLDq0dVz5SLFC/eW6tofkw/O7Ar3lkx5z5U6wzbKDrl2larprp5kk5Q==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.50.0.tgz", + "integrity": "sha512-vwksQWSFZiUhgq3Kv7o1Jcj0DUNylwnIlGvKvLLYsq8pAWha6/WCnXUeaSoNNha/K7QSf2+jvmkxggC1u3pIwQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.49.0", - "@typescript-eslint/type-utils": "5.49.0", - "@typescript-eslint/utils": "5.49.0", + "@typescript-eslint/scope-manager": "5.50.0", + "@typescript-eslint/type-utils": "5.50.0", + "@typescript-eslint/utils": "5.50.0", "debug": "^4.3.4", + "grapheme-splitter": "^1.0.4", "ignore": "^5.2.0", "natural-compare-lite": "^1.4.0", "regexpp": "^3.2.0", @@ -309,14 +310,14 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.49.0.tgz", - "integrity": "sha512-veDlZN9mUhGqU31Qiv2qEp+XrJj5fgZpJ8PW30sHU+j/8/e5ruAhLaVDAeznS7A7i4ucb/s8IozpDtt9NqCkZg==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.50.0.tgz", + "integrity": "sha512-KCcSyNaogUDftK2G9RXfQyOCt51uB5yqC6pkUYqhYh8Kgt+DwR5M0EwEAxGPy/+DH6hnmKeGsNhiZRQxjH71uQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.49.0", - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/typescript-estree": "5.49.0", + "@typescript-eslint/scope-manager": "5.50.0", + "@typescript-eslint/types": "5.50.0", + "@typescript-eslint/typescript-estree": "5.50.0", "debug": "^4.3.4" }, "engines": { @@ -336,13 +337,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.49.0.tgz", - "integrity": "sha512-clpROBOiMIzpbWNxCe1xDK14uPZh35u4QaZO1GddilEzoCLAEz4szb51rBpdgurs5k2YzPtJeTEN3qVbG+LRUQ==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.50.0.tgz", + "integrity": "sha512-rt03kaX+iZrhssaT974BCmoUikYtZI24Vp/kwTSy841XhiYShlqoshRFDvN1FKKvU2S3gK+kcBW1EA7kNUrogg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/visitor-keys": "5.49.0" + "@typescript-eslint/types": "5.50.0", + "@typescript-eslint/visitor-keys": "5.50.0" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -353,13 +354,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.49.0.tgz", - "integrity": "sha512-eUgLTYq0tR0FGU5g1YHm4rt5H/+V2IPVkP0cBmbhRyEmyGe4XvJ2YJ6sYTmONfjmdMqyMLad7SB8GvblbeESZA==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.50.0.tgz", + "integrity": "sha512-dcnXfZ6OGrNCO7E5UY/i0ktHb7Yx1fV6fnQGGrlnfDhilcs6n19eIRcvLBqx6OQkrPaFlDPk3OJ0WlzQfrV0bQ==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "5.49.0", - "@typescript-eslint/utils": "5.49.0", + "@typescript-eslint/typescript-estree": "5.50.0", + "@typescript-eslint/utils": "5.50.0", "debug": "^4.3.4", "tsutils": "^3.21.0" }, @@ -380,9 +381,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.49.0.tgz", - "integrity": "sha512-7If46kusG+sSnEpu0yOz2xFv5nRz158nzEXnJFCGVEHWnuzolXKwrH5Bsf9zsNlOQkyZuk0BZKKoJQI+1JPBBg==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.50.0.tgz", + "integrity": "sha512-atruOuJpir4OtyNdKahiHZobPKFvZnBnfDiyEaBf6d9vy9visE7gDjlmhl+y29uxZ2ZDgvXijcungGFjGGex7w==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -393,13 +394,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.49.0.tgz", - "integrity": "sha512-PBdx+V7deZT/3GjNYPVQv1Nc0U46dAHbIuOG8AZ3on3vuEKiPDwFE/lG1snN2eUB9IhF7EyF7K1hmTcLztNIsA==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.50.0.tgz", + "integrity": "sha512-Gq4zapso+OtIZlv8YNAStFtT6d05zyVCK7Fx3h5inlLBx2hWuc/0465C2mg/EQDDU2LKe52+/jN4f0g9bd+kow==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/visitor-keys": "5.49.0", + "@typescript-eslint/types": "5.50.0", + "@typescript-eslint/visitor-keys": "5.50.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -420,16 +421,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.49.0.tgz", - "integrity": "sha512-cPJue/4Si25FViIb74sHCLtM4nTSBXtLx1d3/QT6mirQ/c65bV8arBEebBJJizfq8W2YyMoPI/WWPFWitmNqnQ==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.50.0.tgz", + "integrity": "sha512-v/AnUFImmh8G4PH0NDkf6wA8hujNNcrwtecqW4vtQ1UOSNBaZl49zP1SHoZ/06e+UiwzHpgb5zP5+hwlYYWYAw==", "dev": true, "dependencies": { "@types/json-schema": "^7.0.9", "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.49.0", - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/typescript-estree": "5.49.0", + "@typescript-eslint/scope-manager": "5.50.0", + "@typescript-eslint/types": "5.50.0", + "@typescript-eslint/typescript-estree": "5.50.0", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0", "semver": "^7.3.7" @@ -446,12 +447,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.49.0.tgz", - "integrity": "sha512-v9jBMjpNWyn8B6k/Mjt6VbUS4J1GvUlR4x3Y+ibnP1z7y7V4n0WRz+50DY6+Myj0UaXVSuUlHohO+eZ8IJEnkg==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.50.0.tgz", + "integrity": "sha512-cdMeD9HGu6EXIeGOh2yVW6oGf9wq8asBgZx7nsR/D36gTfQ0odE5kcRYe5M81vjEFAcPeugXrHg78Imu55F6gg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.49.0", + "@typescript-eslint/types": "5.50.0", "eslint-visitor-keys": "^3.3.0" }, "engines": { @@ -1045,9 +1046,9 @@ } }, "node_modules/eslint": { - "version": "8.32.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.32.0.tgz", - "integrity": "sha512-nETVXpnthqKPFyuY2FNjz/bEd6nbosRgKbkgS/y1C7LJop96gYHWpiguLecMHQ2XCPxn77DS0P+68WzG6vkZSQ==", + "version": "8.33.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.33.0.tgz", + "integrity": "sha512-WjOpFQgKK8VrCnAtl8We0SUOy/oVZ5NHykyMiagV1M9r8IFpIJX7DduK6n1mpfhlG7T1NLWm2SuD8QB7KFySaA==", "dev": true, "dependencies": { "@eslint/eslintrc": "^1.4.1", @@ -1498,9 +1499,9 @@ } }, "node_modules/globals": { - "version": "13.19.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.19.0.tgz", - "integrity": "sha512-dkQ957uSRWHw7CFXLUtUHQI3g3aWApYhfNR2O6jn/907riyTYKVBmxYVROkBcY614FSSeSJh7Xm7SrUWCxvJMQ==", + "version": "13.20.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", + "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -2880,9 +2881,9 @@ } }, "node_modules/typescript": { - "version": "4.9.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", - "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -3292,15 +3293,16 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.49.0.tgz", - "integrity": "sha512-IhxabIpcf++TBaBa1h7jtOWyon80SXPRLDq0dVz5SLFC/eW6tofkw/O7Ar3lkx5z5U6wzbKDrl2larprp5kk5Q==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.50.0.tgz", + "integrity": "sha512-vwksQWSFZiUhgq3Kv7o1Jcj0DUNylwnIlGvKvLLYsq8pAWha6/WCnXUeaSoNNha/K7QSf2+jvmkxggC1u3pIwQ==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "5.49.0", - "@typescript-eslint/type-utils": "5.49.0", - "@typescript-eslint/utils": "5.49.0", + "@typescript-eslint/scope-manager": "5.50.0", + "@typescript-eslint/type-utils": "5.50.0", + "@typescript-eslint/utils": "5.50.0", "debug": "^4.3.4", + "grapheme-splitter": "^1.0.4", "ignore": "^5.2.0", "natural-compare-lite": "^1.4.0", "regexpp": "^3.2.0", @@ -3309,53 +3311,53 @@ } }, "@typescript-eslint/parser": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.49.0.tgz", - "integrity": "sha512-veDlZN9mUhGqU31Qiv2qEp+XrJj5fgZpJ8PW30sHU+j/8/e5ruAhLaVDAeznS7A7i4ucb/s8IozpDtt9NqCkZg==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.50.0.tgz", + "integrity": "sha512-KCcSyNaogUDftK2G9RXfQyOCt51uB5yqC6pkUYqhYh8Kgt+DwR5M0EwEAxGPy/+DH6hnmKeGsNhiZRQxjH71uQ==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "5.49.0", - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/typescript-estree": "5.49.0", + "@typescript-eslint/scope-manager": "5.50.0", + "@typescript-eslint/types": "5.50.0", + "@typescript-eslint/typescript-estree": "5.50.0", "debug": "^4.3.4" } }, "@typescript-eslint/scope-manager": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.49.0.tgz", - "integrity": "sha512-clpROBOiMIzpbWNxCe1xDK14uPZh35u4QaZO1GddilEzoCLAEz4szb51rBpdgurs5k2YzPtJeTEN3qVbG+LRUQ==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.50.0.tgz", + "integrity": "sha512-rt03kaX+iZrhssaT974BCmoUikYtZI24Vp/kwTSy841XhiYShlqoshRFDvN1FKKvU2S3gK+kcBW1EA7kNUrogg==", "dev": true, "requires": { - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/visitor-keys": "5.49.0" + "@typescript-eslint/types": "5.50.0", + "@typescript-eslint/visitor-keys": "5.50.0" } }, "@typescript-eslint/type-utils": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.49.0.tgz", - "integrity": "sha512-eUgLTYq0tR0FGU5g1YHm4rt5H/+V2IPVkP0cBmbhRyEmyGe4XvJ2YJ6sYTmONfjmdMqyMLad7SB8GvblbeESZA==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.50.0.tgz", + "integrity": "sha512-dcnXfZ6OGrNCO7E5UY/i0ktHb7Yx1fV6fnQGGrlnfDhilcs6n19eIRcvLBqx6OQkrPaFlDPk3OJ0WlzQfrV0bQ==", "dev": true, "requires": { - "@typescript-eslint/typescript-estree": "5.49.0", - "@typescript-eslint/utils": "5.49.0", + "@typescript-eslint/typescript-estree": "5.50.0", + "@typescript-eslint/utils": "5.50.0", "debug": "^4.3.4", "tsutils": "^3.21.0" } }, "@typescript-eslint/types": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.49.0.tgz", - "integrity": "sha512-7If46kusG+sSnEpu0yOz2xFv5nRz158nzEXnJFCGVEHWnuzolXKwrH5Bsf9zsNlOQkyZuk0BZKKoJQI+1JPBBg==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.50.0.tgz", + "integrity": "sha512-atruOuJpir4OtyNdKahiHZobPKFvZnBnfDiyEaBf6d9vy9visE7gDjlmhl+y29uxZ2ZDgvXijcungGFjGGex7w==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.49.0.tgz", - "integrity": "sha512-PBdx+V7deZT/3GjNYPVQv1Nc0U46dAHbIuOG8AZ3on3vuEKiPDwFE/lG1snN2eUB9IhF7EyF7K1hmTcLztNIsA==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.50.0.tgz", + "integrity": "sha512-Gq4zapso+OtIZlv8YNAStFtT6d05zyVCK7Fx3h5inlLBx2hWuc/0465C2mg/EQDDU2LKe52+/jN4f0g9bd+kow==", "dev": true, "requires": { - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/visitor-keys": "5.49.0", + "@typescript-eslint/types": "5.50.0", + "@typescript-eslint/visitor-keys": "5.50.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -3364,28 +3366,28 @@ } }, "@typescript-eslint/utils": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.49.0.tgz", - "integrity": "sha512-cPJue/4Si25FViIb74sHCLtM4nTSBXtLx1d3/QT6mirQ/c65bV8arBEebBJJizfq8W2YyMoPI/WWPFWitmNqnQ==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.50.0.tgz", + "integrity": "sha512-v/AnUFImmh8G4PH0NDkf6wA8hujNNcrwtecqW4vtQ1UOSNBaZl49zP1SHoZ/06e+UiwzHpgb5zP5+hwlYYWYAw==", "dev": true, "requires": { "@types/json-schema": "^7.0.9", "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.49.0", - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/typescript-estree": "5.49.0", + "@typescript-eslint/scope-manager": "5.50.0", + "@typescript-eslint/types": "5.50.0", + "@typescript-eslint/typescript-estree": "5.50.0", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0", "semver": "^7.3.7" } }, "@typescript-eslint/visitor-keys": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.49.0.tgz", - "integrity": "sha512-v9jBMjpNWyn8B6k/Mjt6VbUS4J1GvUlR4x3Y+ibnP1z7y7V4n0WRz+50DY6+Myj0UaXVSuUlHohO+eZ8IJEnkg==", + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.50.0.tgz", + "integrity": "sha512-cdMeD9HGu6EXIeGOh2yVW6oGf9wq8asBgZx7nsR/D36gTfQ0odE5kcRYe5M81vjEFAcPeugXrHg78Imu55F6gg==", "dev": true, "requires": { - "@typescript-eslint/types": "5.49.0", + "@typescript-eslint/types": "5.50.0", "eslint-visitor-keys": "^3.3.0" } }, @@ -3825,9 +3827,9 @@ "dev": true }, "eslint": { - "version": "8.32.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.32.0.tgz", - "integrity": "sha512-nETVXpnthqKPFyuY2FNjz/bEd6nbosRgKbkgS/y1C7LJop96gYHWpiguLecMHQ2XCPxn77DS0P+68WzG6vkZSQ==", + "version": "8.33.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.33.0.tgz", + "integrity": "sha512-WjOpFQgKK8VrCnAtl8We0SUOy/oVZ5NHykyMiagV1M9r8IFpIJX7DduK6n1mpfhlG7T1NLWm2SuD8QB7KFySaA==", "dev": true, "requires": { "@eslint/eslintrc": "^1.4.1", @@ -4173,9 +4175,9 @@ } }, "globals": { - "version": "13.19.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.19.0.tgz", - "integrity": "sha512-dkQ957uSRWHw7CFXLUtUHQI3g3aWApYhfNR2O6jn/907riyTYKVBmxYVROkBcY614FSSeSJh7Xm7SrUWCxvJMQ==", + "version": "13.20.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", + "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==", "dev": true, "requires": { "type-fest": "^0.20.2" @@ -5167,9 +5169,9 @@ "dev": true }, "typescript": { - "version": "4.9.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", - "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true }, "uc.micro": { diff --git a/package.json b/package.json index f9648ed..41cd20f 100644 --- a/package.json +++ b/package.json @@ -247,6 +247,11 @@ "command": "lcpr.includeTemplates", "title": "插入头文件模板", "icon": "$(remove)" + }, + { + "command": "lcpr.simpleDebug", + "title": "简单调试", + "icon": "$(remove)" } ], "viewsContainers": { diff --git a/src/controller/DebugController.ts b/src/controller/DebugController.ts new file mode 100644 index 0000000..584a721 --- /dev/null +++ b/src/controller/DebugController.ts @@ -0,0 +1,62 @@ +/* + * Filename: /home/cc/leetcode-vscode/src/controller/DebugController.ts + * Path: /home/cc/leetcode-vscode + * Created Date: Wednesday, February 1st 2023, 11:11:23 am + * Author: ccagml + * + * Copyright (c) 2023 ccagml . All rights reserved + */ + +import { Uri, window } from "vscode"; +import { getTextEditorFilePathByUri } from "../utils/SystemUtils"; +import * as fs from "fs"; +import { fileMeta, ProblemMeta, canDebug } from "../utils/problemUtils"; +import problemTypes from "../utils/problemTypes"; +import { debugExecutor } from "../debug/debugExecutor"; + +// 做杂活 +class DebugContorller { + constructor() {} + + public async debugSolution(uri: Uri, testcase?: string): Promise { + try { + const filePath: string | undefined = await getTextEditorFilePathByUri(uri); + if (!filePath) { + return; + } + const fileContent: Buffer = fs.readFileSync(filePath); + const meta: ProblemMeta | null = fileMeta(fileContent.toString()); + if (!canDebug(meta)) { + return; + } + let result: any; + + if (!testcase) { + result = await debugExecutor.execute( + filePath, + problemTypes[meta!.id]!.testCase.replace(/"/g, '\\"'), + meta!.lang + ); + } else { + const ts: string | undefined = await window.showInputBox({ + prompt: "Enter the test cases.", + validateInput: (s: string): string | undefined => + s && s.trim() ? undefined : "Test case must not be empty.", + placeHolder: "Example: [1,2,3]\\n4", + ignoreFocusOut: true, + }); + if (ts) { + result = await debugExecutor.execute(filePath, ts.replace(/"/g, '\\"'), meta!.lang); + } + } + + if (!result) { + return; + } + } catch (error) { + // + } + } +} + +export const debugContorller: DebugContorller = new DebugContorller(); diff --git a/src/controller/MainController.ts b/src/controller/MainController.ts index 9eca4bb..fa5cfb0 100644 --- a/src/controller/MainController.ts +++ b/src/controller/MainController.ts @@ -12,7 +12,9 @@ import { executeService } from "../service/ExecuteService"; import { ExtensionContext } from "vscode"; import { treeDataService } from "../service/TreeDataService"; import { logOutput } from "../utils/OutputUtils"; +import { extensionState } from "../utils/problemUtils"; +import * as fse from "fs-extra"; // 做杂活 class MainContorller { constructor() {} @@ -30,6 +32,9 @@ class MainContorller { throw new Error("The environment doesn't meet requirements."); } } + if (!(await fse.pathExists(extensionState.cachePath))) { + await fse.mkdirs(extensionState.cachePath); + } } /** @@ -64,6 +69,8 @@ class MainContorller { public initialize(context: ExtensionContext) { this.setGlobal(context); treeDataService.initialize(context); + extensionState.context = context; + extensionState.cachePath = context.globalStoragePath; } // 删除缓存 diff --git a/src/controller/TreeViewController.ts b/src/controller/TreeViewController.ts index 676422f..1428b91 100644 --- a/src/controller/TreeViewController.ts +++ b/src/controller/TreeViewController.ts @@ -57,7 +57,14 @@ import { executeService } from "../service/ExecuteService"; import { getNodeIdFromFile } from "../utils/SystemUtils"; import { logOutput, promptForOpenOutputChannel, promptForSignIn, promptHintMessage } from "../utils/OutputUtils"; import { treeDataService } from "../service/TreeDataService"; -import { genFileExt, genFileName, getyyyymmdd, getDayNowStr } from "../utils/SystemUtils"; +import { + genFileExt, + genFileName, + getyyyymmdd, + getDayNowStr, + getTextEditorFilePathByUri, + usingCmd, +} from "../utils/SystemUtils"; import { IDescriptionConfiguration, isStarShortcut } from "../utils/ConfigUtils"; import * as systemUtils from "../utils/SystemUtils"; import { solutionService } from "../service/SolutionService"; @@ -88,33 +95,6 @@ class TreeViewController implements Disposable { } }, this); } - // 获取当前文件的路径 - /** - * It returns the path of the currently active file, or undefined if there is no active file - * @param [uri] - The file path to open. - * @returns A promise that resolves to a string or undefined. - */ - public async getActiveFilePath(uri?: vscode.Uri): Promise { - let textEditor: vscode.TextEditor | undefined; - if (uri) { - textEditor = await vscode.window.showTextDocument(uri, { - preview: false, - }); - } else { - textEditor = vscode.window.activeTextEditor; - } - - if (!textEditor) { - return undefined; - } - if (textEditor.document.isDirty && !(await textEditor.document.save())) { - vscode.window.showWarningMessage("请先保存当前文件"); - return undefined; - } - return systemUtils.useWsl() - ? systemUtils.toWslPath(textEditor.document.uri.fsPath) - : textEditor.document.uri.fsPath; - } // 提交问题 /** @@ -130,7 +110,7 @@ class TreeViewController implements Disposable { return; } - const filePath: string | undefined = await this.getActiveFilePath(uri); + const filePath: string | undefined = await getTextEditorFilePathByUri(uri); if (!filePath) { return; } @@ -160,7 +140,7 @@ class TreeViewController implements Disposable { return; } - const filePath: string | undefined = await this.getActiveFilePath(uri); + const filePath: string | undefined = await getTextEditorFilePathByUri(uri); if (!filePath) { return; } @@ -277,7 +257,7 @@ class TreeViewController implements Disposable { return; } - const filePath: string | undefined = await this.getActiveFilePath(uri); + const filePath: string | undefined = await getTextEditorFilePathByUri(uri); if (!filePath) { return; } @@ -308,7 +288,7 @@ class TreeViewController implements Disposable { return; } - const filePath: string | undefined = await this.getActiveFilePath(uri); + const filePath: string | undefined = await getTextEditorFilePathByUri(uri); if (!filePath) { return; } @@ -324,26 +304,6 @@ class TreeViewController implements Disposable { } } - /** - * "If the ComSpec environment variable is not set, or if it is set to cmd.exe, then return true." - * - * The ComSpec environment variable is set to the path of the command processor. On Windows, this is - * usually cmd.exe. On Linux, it is usually bash - * @returns A boolean value. - */ - public usingCmd(): boolean { - const comSpec: string | undefined = process.env.ComSpec; - // 'cmd.exe' is used as a fallback if process.env.ComSpec is unavailable. - if (!comSpec) { - return true; - } - - if (comSpec.indexOf("cmd.exe") > -1) { - return true; - } - return false; - } - /** * If you're on Windows, and you're using cmd.exe, then you need to escape double quotes with * backslashes. Otherwise, you don't @@ -358,7 +318,7 @@ class TreeViewController implements Disposable { return `'${test}'`; } - if (this.usingCmd()) { + if (usingCmd()) { // 一般需要走进这里, 除非改了 环境变量ComSpec的值 if (systemUtils.useVscodeNode()) { //eslint-disable-next-line @@ -628,7 +588,7 @@ class TreeViewController implements Disposable { } } else if (!input) { // Triggerred from command - problemInput = await this.getActiveFilePath(); + problemInput = await getTextEditorFilePathByUri(); } if (!problemInput) { @@ -682,7 +642,7 @@ class TreeViewController implements Disposable { return; } try { - let problemInput = await this.getActiveFilePath(); + let problemInput = await getTextEditorFilePathByUri(); // vscode.window.showErrorMessage(twoFactor || "输入错误"); const solution: string = await executeService.getTestApi(problemInput || ""); solutionService.show(solution); diff --git a/src/debug/debugExecutor.ts b/src/debug/debugExecutor.ts new file mode 100644 index 0000000..e4c9e4c --- /dev/null +++ b/src/debug/debugExecutor.ts @@ -0,0 +1,187 @@ +import * as fse from "fs-extra"; +import * as net from "net"; +// import * as path from "path"; +import * as vscode from "vscode"; +import { logOutput } from "../utils/OutputUtils"; +import { fileMeta, getEntryFile } from "../utils/problemUtils"; +import { cppExecutor } from "./executor/cppExecutor"; +import problemTypes from "../utils/problemTypes"; + +export interface IDebugConfig { + type: string; + program?: string; + env?: { + [key: string]: any; + }; + [x: string]: any; +} + +const debugConfigMap: Map = new Map([ + [ + "javascript", + { + type: "node", + }, + ], + [ + "python3", + { + type: "python", + env: { + PYTHONPATH: "", + }, + }, + ], +]); + +export interface IProblemType { + funName: string; + paramTypes: string[]; + returnType: string; + testCase: string; + specialFunName?: { + [x: string]: string; + }; +} + +interface IDebugResult { + type: "success" | "error"; + message: string; + problemNum: number; + language: string; + filePath: string; + testString: string; +} + +class DebugExecutor { + private server: net.Server; + + constructor() { + this.start(); + } + + public async execute(filePath: string, testString: string, language: string): Promise { + if (this.server == null || this.server.address() == null) { + vscode.window.showErrorMessage("Debug server error, maybe you can restart vscode."); + } + + if (language === "cpp") { + await cppExecutor.execute(filePath, testString, language, (this.server.address() as net.AddressInfo).port); + return; + } + + const debugConfig: undefined | IDebugConfig = debugConfigMap.get(language); + if (debugConfig == null) { + vscode.window.showErrorMessage("Notsupported language."); + return; + } + + const fileContent: Buffer = await fse.readFile(filePath); + const meta: { id: string; lang: string } | null = fileMeta(fileContent.toString()); + if (meta == null) { + vscode.window.showErrorMessage( + "File meta info has been changed, please check the content: '@lc app=leetcode.cn id=xx lang=xx'." + ); + return; + } + const problemType: IProblemType = problemTypes[meta.id]; + if (problemType == null) { + vscode.window.showErrorMessage(`Notsupported problem: ${meta.id}.`); + return; + } + + debugConfig.program = await getEntryFile(meta.lang, meta.id); + + const funName: string = this.getProblemFunName(language, problemType); + + if (language === "javascript") { + // check whether module.exports is exist or not + const moduleExportsReg: RegExp = new RegExp(`module.exports = ${problemType.funName};`); + if (!moduleExportsReg.test(fileContent.toString())) { + fse.writeFile( + filePath, + fileContent.toString() + + `\n// @after-stub-for-debug-begin\nmodule.exports = ${funName};\n// @after-stub-for-debug-end` + ); + } + } else if (language === "python3") { + // check whether module.exports is exist or not + const moduleExportsReg: RegExp = /# @before-stub-for-debug-begin/; + if (!moduleExportsReg.test(fileContent.toString())) { + await fse.writeFile( + filePath, + `# @before-stub-for-debug-begin\nfrom python3problem${meta.id} import *\nfrom typing import *\n# @before-stub-for-debug-end\n\n` + + fileContent.toString() + ); + } + debugConfig.env!.PYTHONPATH = debugConfig.program; + } + + const args: string[] = [ + filePath, + testString, + problemType.funName, + problemType.paramTypes.join(","), + problemType.returnType, + meta.id, + (this.server.address() as net.AddressInfo).port.toString(), + ]; + vscode.debug.startDebugging( + undefined, + Object.assign({}, debugConfig, { + request: "launch", + name: "Launch Program", + args, + }) + ); + + return; + } + + /** + * for some problem have special function name + * @param language + * @param problemType + */ + private getProblemFunName(language: string, problemType: IProblemType): string { + if (problemType.specialFunName && problemType.specialFunName[language]) { + return problemType.specialFunName[language]; + } + return problemType.funName; + } + + private async start(): Promise { + this.server = net.createServer((clientSock: net.Socket) => { + clientSock.setEncoding("utf8"); + + clientSock.on("data", async (data: Buffer) => { + const result: IDebugResult = JSON.parse(data.toString()); + if (result.type === "error") { + vscode.window.showErrorMessage(result.message); + } else { + // const leetcodeResult: string = await leetCodeExecutor.testSolution( + // result.filePath, + // parseTestString(result.testString.replace(/\\"/g, '"')), + // ); + // if (!leetcodeResult) { + // return; + // } + // leetCodeSubmissionProvider.show(leetcodeResult); + } + }); + + clientSock.on("error", (error: Error) => { + logOutput.appendLine(error.toString()); + }); + }); + + this.server.on("error", (error: Error) => { + logOutput.appendLine(error.toString()); + }); + + // listen on a random port + this.server.listen({ port: 0, host: "127.0.0.1" }); + } +} + +export const debugExecutor: DebugExecutor = new DebugExecutor(); diff --git a/src/debug/entry/cpp/entry.cpp b/src/debug/entry/cpp/entry.cpp new file mode 100644 index 0000000..9dd4dbf --- /dev/null +++ b/src/debug/entry/cpp/entry.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +#include "cJSON.h" + +using namespace std; + +// @@stub-for-include-code@@ + +int main(int argc, char **argv) +{ + for (int i = 0; i < argc; i++) + { + cout << "Argument " << i << " is " << argv[i] << endl; + } + + // @@stub-for-body-code@@ + + // for (int i = 0; i < params.size(); i++) + // { + // string param = params[i]; + // string paramType = paramsType[i]; + // cJSON *item = cJSON_Parse(param.c_str()); + // if (paramType == "number") + // { + // int num = parseNumber(item); + // res.push_back(&num); + // } + // else if (paramType == "number[]") + // { + // vector vint = parseNumberArray(item); + // res.push_back(&vint); + // } + // } + + return 0; +} diff --git a/src/debug/entry/cpp/problems/116.cpp b/src/debug/entry/cpp/problems/116.cpp new file mode 100644 index 0000000..5c09efa --- /dev/null +++ b/src/debug/entry/cpp/problems/116.cpp @@ -0,0 +1,46 @@ +Node *parseNodeElement(cJSON *node) +{ + if (node->type != cJSON_Number) + { + return nullptr; + } + return new Node(node->valueint); +} + +Node *parseNode(const cJSON *node) +{ + if (node->type != cJSON_Array) + { + throw "Parse parameter error, expect NumberArray"; + } + + int i = 0; + int isLeft = true; + Node *first = parseNodeElement(cJSON_GetArrayItem(node, i)); + queue q; + q.push(first); + int size = cJSON_GetArraySize(node); + + for (i = 1; i < size; i++) + { + Node *top = q.front(); + Node *child = parseNodeElement(cJSON_GetArrayItem(node, i)); + if (isLeft) + { + top->left = child; + isLeft = false; + } + else + { + top->right = child; + isLeft = true; + q.pop(); + } + if (child != nullptr) + { + q.push(child); + } + } + + return first; +} diff --git a/src/debug/entry/cpp/problems/116.h b/src/debug/entry/cpp/problems/116.h new file mode 100644 index 0000000..a684aca --- /dev/null +++ b/src/debug/entry/cpp/problems/116.h @@ -0,0 +1,17 @@ +class Node +{ +public: + int val; + Node *left; + Node *right; + Node *next; + + Node() : val(0), left(NULL), right(NULL), next(NULL) {} + + Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {} + + Node(int _val, Node *_left, Node *_right, Node *_next) + : val(_val), left(_left), right(_right), next(_next) {} +}; + +Node *parseNode(const cJSON *node); diff --git a/src/debug/entry/cpp/problems/133.cpp b/src/debug/entry/cpp/problems/133.cpp new file mode 100644 index 0000000..a23a9cc --- /dev/null +++ b/src/debug/entry/cpp/problems/133.cpp @@ -0,0 +1,19 @@ +Node *parseNode(const vector> vec) +{ + vector arr{}; + int i = 0; + int j = 0; + for (i = 0; i < vec.size(); i++) + { + vector nei{}; + arr.push_back(new Node(i + 1, nei)); + } + for (i = 0; i < vec.size(); i++) + { + for (j = 0; j < vec[i].size(); j++) + { + arr[i]->neighbors.push_back(arr[vec[i][j] - 1]); + } + } + return arr[0]; +} diff --git a/src/debug/entry/cpp/problems/133.h b/src/debug/entry/cpp/problems/133.h new file mode 100644 index 0000000..69dbcea --- /dev/null +++ b/src/debug/entry/cpp/problems/133.h @@ -0,0 +1,16 @@ +class Node +{ +public: + int val; + vector neighbors; + + Node() {} + + Node(int _val, vector _neighbors) + { + val = _val; + neighbors = _neighbors; + } +}; + +Node *parseNode(const vector> vec); diff --git a/src/debug/entry/cpp/problems/138.cpp b/src/debug/entry/cpp/problems/138.cpp new file mode 100644 index 0000000..23b4444 --- /dev/null +++ b/src/debug/entry/cpp/problems/138.cpp @@ -0,0 +1,45 @@ +Node *parseValueElement(cJSON *node) +{ + int size = cJSON_GetArraySize(node); + if (node->type != cJSON_Array && size == 2) + { + throw "Parse parameter error, expect NumberArray with length: 2"; + } + int value = parseNumber(cJSON_GetArrayItem(node, 0)); + return new Node(value); +} + +int parseRandomElement(cJSON *node) +{ + cJSON *child = cJSON_GetArrayItem(node, 1); + + if (child->type != cJSON_Number) + { + return -1; + } + return child->valueint; +} + +Node *parseNode(vector vec) +{ + vector arr{}; + int i = 0; + for (i = 0; i < vec.size(); i++) + { + arr.push_back(parseValueElement(vec[i])); + } + for (i = 0; i < vec.size(); i++) + { + if (i != vec.size()) + { + arr[i]->next = arr[i + 1]; + } + int el = parseRandomElement(vec[i]); + if (el != -1) + { + arr[i]->random = arr[el]; + } + } + + return arr[0]; +} diff --git a/src/debug/entry/cpp/problems/138.h b/src/debug/entry/cpp/problems/138.h new file mode 100644 index 0000000..8845622 --- /dev/null +++ b/src/debug/entry/cpp/problems/138.h @@ -0,0 +1,16 @@ +class Node +{ +public: + int val; + Node *next; + Node *random; + + Node(int _val) + { + val = _val; + next = NULL; + random = NULL; + } +}; + +Node *parseNode(vector vec); diff --git a/src/debug/entry/cpp/problems/278.cpp b/src/debug/entry/cpp/problems/278.cpp new file mode 100644 index 0000000..b5d5def --- /dev/null +++ b/src/debug/entry/cpp/problems/278.cpp @@ -0,0 +1,10 @@ +int badVersion = 0; + +bool isBadVersion(int version) +{ + if (version >= badVersion) + { + return true; + } + return false; +} diff --git a/src/debug/entry/cpp/problems/278.h b/src/debug/entry/cpp/problems/278.h new file mode 100644 index 0000000..c089094 --- /dev/null +++ b/src/debug/entry/cpp/problems/278.h @@ -0,0 +1,2 @@ +extern int badVersion; +bool isBadVersion(int version); diff --git a/src/debug/entry/cpp/problems/429.cpp b/src/debug/entry/cpp/problems/429.cpp new file mode 100644 index 0000000..69372a6 --- /dev/null +++ b/src/debug/entry/cpp/problems/429.cpp @@ -0,0 +1,47 @@ +Node *parseNodeElement(cJSON *node) +{ + if (node->type != cJSON_Number) + { + return nullptr; + } + vector child{}; + return new Node(node->valueint, child); +} + +Node *parseNode(const cJSON *node) +{ + if (node->type != cJSON_Array) + { + throw "Parse parameter error, expect NumberArray"; + } + + int size = cJSON_GetArraySize(node); + + if (size == 0) + { + return nullptr; + } + + int i = 0; + int isLeft = true; + Node *first = parseNodeElement(cJSON_GetArrayItem(node, i)); + queue q; + q.push(first); + + for (i = 2; i < size; i++) + { + Node *top = q.front(); + Node *child = parseNodeElement(cJSON_GetArrayItem(node, i)); + if (child == nullptr) + { + q.pop(); + } + else + { + top->children.push_back(child); + q.push(child); + } + } + + return first; +} diff --git a/src/debug/entry/cpp/problems/429.h b/src/debug/entry/cpp/problems/429.h new file mode 100644 index 0000000..11ae134 --- /dev/null +++ b/src/debug/entry/cpp/problems/429.h @@ -0,0 +1,21 @@ +class Node +{ +public: + int val; + vector children; + + Node() {} + + Node(int _val) + { + val = _val; + } + + Node(int _val, vector _children) + { + val = _val; + children = _children; + } +}; + +Node *parseNode(const cJSON *node); diff --git a/src/debug/entry/cpp/problems/843.cpp b/src/debug/entry/cpp/problems/843.cpp new file mode 100644 index 0000000..a06b097 --- /dev/null +++ b/src/debug/entry/cpp/problems/843.cpp @@ -0,0 +1,18 @@ +string secret = ""; + +int Master::guess(string word) +{ + int match = 0; + for (int i = 0; i < word.length(); i++) + { + if (word[i] == secret[i]) + { + match += 1; + } + } + if (match == 0) + { + return -1; + } + return match; +} diff --git a/src/debug/entry/cpp/problems/843.h b/src/debug/entry/cpp/problems/843.h new file mode 100644 index 0000000..d8c448d --- /dev/null +++ b/src/debug/entry/cpp/problems/843.h @@ -0,0 +1,7 @@ +extern string secret; + +class Master +{ +public: + int guess(string word); +}; diff --git a/src/debug/entry/cpp/problems/common.cpp b/src/debug/entry/cpp/problems/common.cpp new file mode 100644 index 0000000..c4c5284 --- /dev/null +++ b/src/debug/entry/cpp/problems/common.cpp @@ -0,0 +1,292 @@ +#include +#include +using namespace std; + +#include "cJSON.h" + +// @@stub-for-include-code@@ + +int parseNumber(cJSON *node) +{ + if (node->type != cJSON_Number) + { + throw "Parse parameter error, expect Number"; + } + return node->valueint; +} + +vector parseNumberArray(cJSON *node) +{ + if (node->type != cJSON_Array) + { + throw "Parse parameter error, expect NumberArray"; + } + + vector res{}; + + for (int i = 0; i < cJSON_GetArraySize(node); i++) + { + cJSON *item = cJSON_GetArrayItem(node, i); + res.push_back(parseNumber(item)); + } + return res; +} + +vector> parseNumberArrayArray(cJSON *node) +{ + if (node->type != cJSON_Array) + { + throw "Parse parameter error, expect NumberArrayArray"; + } + + vector> res{}; + + for (int i = 0; i < cJSON_GetArraySize(node); i++) + { + cJSON *item = cJSON_GetArrayItem(node, i); + res.push_back(parseNumberArray(item)); + } + return res; +} + +string parseString(cJSON *node) +{ + if (node->type != cJSON_String) + { + throw "Parse parameter error, expect Number"; + } + return node->valuestring; +} + +vector parseStringArray(cJSON *node) +{ + if (node->type != cJSON_Array) + { + throw "Parse parameter error, expect StringArray"; + } + + vector res{}; + + for (int i = 0; i < cJSON_GetArraySize(node); i++) + { + cJSON *item = cJSON_GetArrayItem(node, i); + res.push_back(parseString(item)); + } + return res; +} + +vector> parseStringArrayArray(cJSON *node) +{ + if (node->type != cJSON_Array) + { + throw "Parse parameter error, expect StringArray"; + } + + vector> res{}; + + for (int i = 0; i < cJSON_GetArraySize(node); i++) + { + cJSON *item = cJSON_GetArrayItem(node, i); + res.push_back(parseStringArray(item)); + } + return res; +} + +char parseCharacter(cJSON *node) +{ + string res = parseString(node); + return res[0]; +} + +vector parseCharacterArray(cJSON *node) +{ + if (node->type != cJSON_Array) + { + throw "Parse parameter error, expect parseCharacterArray"; + } + + vector res{}; + + for (int i = 0; i < cJSON_GetArraySize(node); i++) + { + cJSON *item = cJSON_GetArrayItem(node, i); + res.push_back(parseCharacter(item)); + } + return res; +} + +vector> parseCharacterArrayArray(cJSON *node) +{ + if (node->type != cJSON_Array) + { + throw "Parse parameter error, expect StringArray"; + } + + vector> res{}; + + for (int i = 0; i < cJSON_GetArraySize(node); i++) + { + cJSON *item = cJSON_GetArrayItem(node, i); + res.push_back(parseCharacterArray(item)); + } + return res; +} + +ListNode *parseListNode(const vector &vec) +{ + ListNode *head = nullptr; + ListNode *current = nullptr; + for (int i = 0; i < vec.size(); i++) + { + if (i == 0) + { + head = new ListNode(vec[i]); + current = head; + } + else + { + current->next = new ListNode(vec[i]); + current = current->next; + } + } + return head; +} + +vector parseListNodeArray(const vector> &vec) +{ + vector res{}; + for (int i = 0; i < vec.size(); i++) + { + res.push_back(parseListNode(vec[i])); + } + return res; +} + +vector parseNestedIntegerArray(cJSON *node) +{ + vector res{}; + + for (int i = 0; i < cJSON_GetArraySize(node); i++) + { + cJSON *item = cJSON_GetArrayItem(node, i); + res.push_back(NestedInteger(item)); + } + return res; +} + +NestedInteger::NestedInteger(cJSON *node) +{ + if (node->type != cJSON_Array) + { + this->value = parseNumber(node); + } + else + { + this->list = parseNestedIntegerArray(node); + } +} + +bool NestedInteger::isInteger() const +{ + return this->list.size() == 0; +} + +int NestedInteger::getInteger() const +{ + if (this->isInteger()) + { + return this->value; + } + return -1; +} + +const vector &NestedInteger::getList() const +{ + return this->list; +} + +MountainArray::MountainArray(const vector &vec) +{ + this->value = vec; +} + +int MountainArray::get(int index) +{ + if (index >= this->value.size()) + { + return -1; + } + return this->value[index]; +} + +int MountainArray::length() +{ + return this->value.size(); +} + +TreeNode *parseTreeNodeElement(cJSON *node) +{ + if (node->type != cJSON_Number) + { + return nullptr; + } + return new TreeNode(node->valueint); +} + +TreeNode *parseTreeNode(const cJSON *node) +{ + TreeNode *root = nullptr; + TreeNode *parent = nullptr; + queue q; + int i = 0; + + if (node->type != cJSON_Array) + { + throw "Parse parameter error, expect NumberArray"; + } + int size = cJSON_GetArraySize(node); + + while (i < size) + { + if (i == 0) + { + TreeNode *child = parseTreeNodeElement(cJSON_GetArrayItem(node, i)); + root = child; + i += 1; + q.push(root); + continue; + } + + parent = q.front(); + q.pop(); + TreeNode *left = parseTreeNodeElement(cJSON_GetArrayItem(node, i)); + if (left != nullptr) + { + parent->left = left; + q.push(left); + } + if (i + 1 < size) + { + TreeNode *right = parseTreeNodeElement(cJSON_GetArrayItem(node, i + 1)); + if (right != nullptr) + { + parent->right = right; + q.push(right); + } + } + i = i + 2; + } + return root; +} + +vector parsecJSONArray(const cJSON *node) +{ + vector res{}; + for (int i = 0; i < cJSON_GetArraySize(node); i++) + { + res.push_back(cJSON_GetArrayItem(node, i)); + } + return res; +} + +// @@stub-for-problem-define-code@@ diff --git a/src/debug/entry/cpp/problems/common.h b/src/debug/entry/cpp/problems/common.h new file mode 100644 index 0000000..deeec40 --- /dev/null +++ b/src/debug/entry/cpp/problems/common.h @@ -0,0 +1,81 @@ + +#ifndef COMMON_DEFINE +#define COMMON_DEFINE + +#include +#include +#include +using namespace std; + +struct ListNode { + int val; + ListNode *next; + ListNode() : val(0), next(nullptr) {} + ListNode(int x) : val(x), next(nullptr) {} + ListNode(int x, ListNode *next) : val(x), next(next) {} +}; + +int parseNumber(cJSON *node); +vector parseNumberArray(cJSON *node); +vector> parseNumberArrayArray(cJSON *node); +string parseString(cJSON *node); +vector parseStringArray(cJSON *node); +vector> parseStringArrayArray(cJSON *node); +char parseCharacter(cJSON *node); +vector parseCharacterArray(cJSON *node); +vector> parseCharacterArrayArray(cJSON *node); +ListNode *parseListNode(const vector &vec); +vector parseListNodeArray(const vector> &vec); + +class NestedInteger +{ +private: + vector list{}; + int value; + +public: + NestedInteger(cJSON *node); + + // Return true if this NestedInteger holds a single integer, rather than a nested list. + bool isInteger() const; + + // Return the single integer that this NestedInteger holds, if it holds a single integer + // The result is undefined if this NestedInteger holds a nested list + int getInteger() const; + + // Return the nested list that this NestedInteger holds, if it holds a nested list + // The result is undefined if this NestedInteger holds a single integer + const vector &getList() const; +}; + +vector parseNestedIntegerArray(cJSON *node); + +class MountainArray +{ +private: + vector value{}; + +public: + MountainArray(const vector &ve); + int get(int index); + int length(); +}; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) + { + } +}; + +TreeNode *parseTreeNodeElement(cJSON *node); +TreeNode *parseTreeNode(const cJSON *node); + +vector parsecJSONArray(const cJSON *node); + +// @@stub-for-problem-define-code@@ + +#endif diff --git a/src/debug/entry/javascript/entry.js b/src/debug/entry/javascript/entry.js new file mode 100644 index 0000000..a9a326d --- /dev/null +++ b/src/debug/entry/javascript/entry.js @@ -0,0 +1,371 @@ +var net = require("net"); + +const fun = require(process.argv[2]); +const testString = process.argv[3]; +const paramTypes = process.argv[5].split(","); +const problemNum = parseInt(process.argv[7]); +const debugServerPort = parseInt(process.argv[8]); + +const sock = net.connect( + { + port: debugServerPort, + host: "127.0.0.1", + }, + function() { + start(); + }, +); +sock.setNoDelay(true); + +function onClose() { + setTimeout(() => { + if (sock != null) { + sock.end(); + } + process.exit(0); + }, 2000); +} + +function makeMessage(type, message) { + return JSON.stringify({ + type, + message, + problemNum, + filePath: process.argv[2], + testString, + language: "javascript", + }); +} + +function onError(err) { + sock.write(makeMessage("error", err)); + onClose(); +} + +function onSuccess() { + sock.write(makeMessage("success", "")); + onClose(); +} + +process.on("uncaughtException", function(err) { + onError(err.message + "\n" + err.stack); + throw err; +}); + +function onParameterError() { + throw new Error("Parameters parsing error, please check the format of the input parameters"); +} + +function onParameterTypeError(type) { + throw new Error(`Unsupported parameter type: ${type}`); +} + +function isNumber(num) { + return num === +num; +} + +function isString(str) { + return typeof str === "string"; +} + +function isCharacter(str) { + return isString(str) && str.length === 1; +} + +function parseNumber(param) { + if (!isNumber(param)) { + onParameterError(); + } + return param; +} + +function parseNumberArray(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + param.map(p => { + if (!isNumber(p)) { + onParameterError(); + } + }); + return param; +} + +function parseString(param) { + if (!isString(param)) { + onParameterError(); + } + return param; +} + +function parseStringArray(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + param.map(p => { + if (!isString(p)) { + onParameterError(); + } + }); + return param; +} + +function parseStringArrayArray(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + param.map(p => { + if (!parseStringArray(p)) { + onParameterError(); + } + }); + return param; +} + +function ListNode(val) { + this.val = val; + this.next = null; +} + +function parseListNode(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + + let head = null; + let tail = null; + param.map(p => { + const node = new ListNode(p); + if (head == null) { + tail = node; + head = node; + } else { + tail.next = node; + tail = node; + } + }); + return head; +} + +function parseListNodeArray(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + + const res = param.map(p => { + return parseListNode(p); + }); + return res; +} + +function parseNumberArrayArray(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + param.map(p => { + return parseNumberArray(p); + }); + return param; +} + +function parseCharacter(param) { + if (!isCharacter(param)) { + onParameterError(); + } + return param; +} + +function parseCharacterArray(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + param.map(p => { + if (!isCharacter(p)) { + onParameterError(); + } + }); + return param; +} + +function parseCharacterArrayArray(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + param.map(p => { + parseCharacterArray(p); + }); + return param; +} + +function NestedInteger(ni) { + let nested = []; + if (Array.isArray(ni)) { + ni.map(n => { + nested.push(new NestedInteger(n)); + }); + } + + /** + * Return true if this NestedInteger holds a single integer, rather than a nested list. + * @return { boolean } + */ + this.isInteger = function() { + if (Array.isArray(ni)) { + return false; + } + return true; + }; + + /** + * Return the single integer that this NestedInteger holds, if it holds a single integer + * Return null if this NestedInteger holds a nested list + * @return { integer } + */ + this.getInteger = function() { + if (Array.isArray(ni)) { + return null; + } + return ni; + }; + + /** + * Return the nested list that this NestedInteger holds, if it holds a nested list + * Return null if this NestedInteger holds a single integer + * @return { NestedInteger[] } + */ + this.getList = function() { + if (Array.isArray(ni)) { + return nested; + } + return null; + }; +} + +function parseNestedIntegerArray(param) { + return param.map(p => { + return new NestedInteger(p); + }); +} + +function parseMountainArray(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + function MountainArray() { + /** + * @param {integer} index + * @return {integer} + */ + this.get = function(index) { + return param[index]; + }; + + /** + * @return {integer} + */ + this.length = function() { + return param.length; + }; + } + return new MountainArray(); +} + +function TreeNode(val) { + this.val = val; + this.left = this.right = null; +} + +function parseTreeNode(param) { + if (!Array.isArray(param)) { + onParameterError(); + } + + let root = null; + const fifo = []; + let i = 0; + while (i < param.length) { + if (i === 0) { + root = new TreeNode(param[i]); + i += 1; + fifo.push(root); + continue; + } + const parent = fifo.shift(); + if (param[i] != null) { + const left = new TreeNode(param[i]); + parent.left = left; + fifo.push(left); + } + if (i + 1 < param.length && param[i + 1] != null) { + const right = new TreeNode(param[i + 1]); + parent.right = right; + fifo.push(right); + } + i = i + 2; + } + return root; +} + +function parseParameter(index, type, param) { + switch (type) { + case "number": + return parseNumber(param); + case "number[]": + return parseNumberArray(param); + case "number[][]": + return parseNumberArrayArray(param); + case "string": + return parseString(param); + case "string[]": + return parseStringArray(param); + case "string[][]": + return parseStringArrayArray(param); + case "ListNode": + return parseListNode(param); + case "ListNode[]": + return parseListNodeArray(param); + case "character": + return parseCharacter(param); + case "character[]": + return parseCharacterArray(param); + case "character[][]": + return parseCharacterArrayArray(param); + case "NestedInteger[]": + return parseNestedIntegerArray(param); + case "MountainArray": + return parseMountainArray(param); + case "TreeNode": + return parseTreeNode(param); + } + const result = parseSpecialParameter(index, type, param); + if (result == null) { + onParameterTypeError(type); + } + return result; +} + +// @@stub-for-code@@ + +function parseParamsToJson(paramString) { + let params; + try { + const paramsByLine = paramString.split(/\\n/); + + params = paramsByLine.map(str => { + return JSON.parse(str); + }); + + return params; + } catch (error) { + onParameterError(); + return; + } +} + +function start() { + const paramString = testString.replace(/\\"/g, '"'); + const jsonParams = parseParamsToJson(paramString); + + runUserScript(fun, jsonParams, paramTypes); + onSuccess(); +} diff --git a/src/debug/entry/javascript/problems/1095.js b/src/debug/entry/javascript/problems/1095.js new file mode 100644 index 0000000..c7feabf --- /dev/null +++ b/src/debug/entry/javascript/problems/1095.js @@ -0,0 +1,11 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== 2) { + onParameterError(); + } + userFunm.apply(null, [parseParameter(0, 'number', params[1]), parseParameter(1, 'MountainArray', params[0])]); +} + + +function parseSpecialParameter(index, type, param) { + return null; +} diff --git a/src/debug/entry/javascript/problems/116.js b/src/debug/entry/javascript/problems/116.js new file mode 100644 index 0000000..a8be77a --- /dev/null +++ b/src/debug/entry/javascript/problems/116.js @@ -0,0 +1,45 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + userFunm.apply(null, parsedParams); +} + +function Node(val, left, right, next) { + this.val = val; + this.left = left; + this.right = right; + this.next = next; +} + +/** + * @param {number[]} param + */ +function parseNode(nums) { + const arr = []; + nums.map((n, i) => { + const node = new Node(n); + arr.push(node); + if (i !== 0) { + if (i % 2 === 1) { + arr[(i - 1) / 2].left = node; + } else { + arr[(i - 2) / 2].right = node; + } + } + }); + return arr[0]; +} + +function parseSpecialParameter(index, type, param) { + switch (type) { + case "Node": + return parseNode(param); + } + return null; +} diff --git a/src/debug/entry/javascript/problems/117.js b/src/debug/entry/javascript/problems/117.js new file mode 100644 index 0000000..039112d --- /dev/null +++ b/src/debug/entry/javascript/problems/117.js @@ -0,0 +1,52 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + userFunm.apply(null, parsedParams); +} + +function Node(val, left, right, next) { + this.val = val === undefined ? null : val; + this.left = left === undefined ? null : left; + this.right = right === undefined ? null : right; + this.next = next === undefined ? null : next; +} + +/** + * @param {number[]} param + */ +function parseNode(param) { + if (param.length == 0) { + return null; + } + const first = new Node(param[0]); + const queue = [[first, 0]]; + for (let j = 1; j < param.length; j++) { + const top = queue[0]; + const val = param[j] === null ? null : new Node(param[j]); + if (top[1] === 0) { + top[0].left = val; + top[1] = 1; + } else { + top[0].right = val; + queue.shift(); + } + if (val !== null) { + queue.push([val, 0]); + } + } + return first; +} + +function parseSpecialParameter(index, type, param) { + switch (type) { + case "Node": + return parseNode(param); + } + return null; +} diff --git a/src/debug/entry/javascript/problems/133.js b/src/debug/entry/javascript/problems/133.js new file mode 100644 index 0000000..b123b31 --- /dev/null +++ b/src/debug/entry/javascript/problems/133.js @@ -0,0 +1,40 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + userFunm.apply(null, parsedParams); +} + +function Node(val, neighbors) { + this.val = val; + this.neighbors = neighbors; +} + +/** + * @param {number[][]} param + */ +function parseNode(nums) { + const arr = []; + nums.map((n, i) => { + arr.push(new Node(i + 1, [])); + }); + nums.map((nei, i) => { + nei.map(k => { + arr[i].neighbors.push(arr[k - 1]); + }); + }); + return arr[0]; +} + +function parseSpecialParameter(index, type, param) { + switch (type) { + case "Node": + return parseNode(param); + } + return null; +} diff --git a/src/debug/entry/javascript/problems/138.js b/src/debug/entry/javascript/problems/138.js new file mode 100644 index 0000000..709b1be --- /dev/null +++ b/src/debug/entry/javascript/problems/138.js @@ -0,0 +1,44 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + userFunm.apply(null, parsedParams); +} + +function Node(val, next, random) { + this.val = val; + this.next = next; + this.random = random; +} + +/** + * @param {number[][]} param + */ +function parseNode(nums) { + const arr = []; + nums.map((n, i) => { + arr.push(new Node(n[0], null, null)); + }); + nums.map((n, i) => { + if (i !== nums.length - 1) { + arr[i].next = arr[i + 1]; + } + if (n[1] !== null) { + arr[i].random = arr[n[1]]; + } + }); + return arr[0]; +} + +function parseSpecialParameter(index, type, param) { + switch (type) { + case "Node": + return parseNode(param); + } + return null; +} diff --git a/src/debug/entry/javascript/problems/278.js b/src/debug/entry/javascript/problems/278.js new file mode 100644 index 0000000..6e14d71 --- /dev/null +++ b/src/debug/entry/javascript/problems/278.js @@ -0,0 +1,19 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== 2) { + onParameterError(); + } + const version = params[1]; + const n = params[0]; + const isBadVersion = function (k) { + if (k >= version) { + return true; + } + return false; + } + userFunm(isBadVersion)(n); +} + + +function parseSpecialParameter(index, type, param) { + return null; +} diff --git a/src/debug/entry/javascript/problems/341.js b/src/debug/entry/javascript/problems/341.js new file mode 100644 index 0000000..d1ef8c0 --- /dev/null +++ b/src/debug/entry/javascript/problems/341.js @@ -0,0 +1,18 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + + const i = new userFunm(parsedParams[0]); + const a = []; + while (i.hasNext()) a.push(i.next()); +} + +function parseSpecialParameter(index, type, param) { + return null; +} diff --git a/src/debug/entry/javascript/problems/429.js b/src/debug/entry/javascript/problems/429.js new file mode 100644 index 0000000..6b365d3 --- /dev/null +++ b/src/debug/entry/javascript/problems/429.js @@ -0,0 +1,46 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + userFunm.apply(null, parsedParams); +} + +function Node(val, children) { + this.val = val; + this.children = children; +} + +/** + * @param {number[]} param + */ +function parseNode(param) { + if (param.length === 0) { + return null; + } + const first = new Node(param[0], []); + const queue = [first]; + for (let j = 2; j < param.length; j++) { + const top = queue[0]; + if (param[j] === null) { + queue.shift(); + } else { + const child = new Node(param[j], []); + top.children.push(child); + queue.push(child); + } + } + return first; +} + +function parseSpecialParameter(index, type, param) { + switch (type) { + case "Node": + return parseNode(param); + } + return null; +} diff --git a/src/debug/entry/javascript/problems/559.js b/src/debug/entry/javascript/problems/559.js new file mode 100644 index 0000000..6b365d3 --- /dev/null +++ b/src/debug/entry/javascript/problems/559.js @@ -0,0 +1,46 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + userFunm.apply(null, parsedParams); +} + +function Node(val, children) { + this.val = val; + this.children = children; +} + +/** + * @param {number[]} param + */ +function parseNode(param) { + if (param.length === 0) { + return null; + } + const first = new Node(param[0], []); + const queue = [first]; + for (let j = 2; j < param.length; j++) { + const top = queue[0]; + if (param[j] === null) { + queue.shift(); + } else { + const child = new Node(param[j], []); + top.children.push(child); + queue.push(child); + } + } + return first; +} + +function parseSpecialParameter(index, type, param) { + switch (type) { + case "Node": + return parseNode(param); + } + return null; +} diff --git a/src/debug/entry/javascript/problems/589.js b/src/debug/entry/javascript/problems/589.js new file mode 100644 index 0000000..6b365d3 --- /dev/null +++ b/src/debug/entry/javascript/problems/589.js @@ -0,0 +1,46 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + userFunm.apply(null, parsedParams); +} + +function Node(val, children) { + this.val = val; + this.children = children; +} + +/** + * @param {number[]} param + */ +function parseNode(param) { + if (param.length === 0) { + return null; + } + const first = new Node(param[0], []); + const queue = [first]; + for (let j = 2; j < param.length; j++) { + const top = queue[0]; + if (param[j] === null) { + queue.shift(); + } else { + const child = new Node(param[j], []); + top.children.push(child); + queue.push(child); + } + } + return first; +} + +function parseSpecialParameter(index, type, param) { + switch (type) { + case "Node": + return parseNode(param); + } + return null; +} diff --git a/src/debug/entry/javascript/problems/590.js b/src/debug/entry/javascript/problems/590.js new file mode 100644 index 0000000..6b365d3 --- /dev/null +++ b/src/debug/entry/javascript/problems/590.js @@ -0,0 +1,46 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + userFunm.apply(null, parsedParams); +} + +function Node(val, children) { + this.val = val; + this.children = children; +} + +/** + * @param {number[]} param + */ +function parseNode(param) { + if (param.length === 0) { + return null; + } + const first = new Node(param[0], []); + const queue = [first]; + for (let j = 2; j < param.length; j++) { + const top = queue[0]; + if (param[j] === null) { + queue.shift(); + } else { + const child = new Node(param[j], []); + top.children.push(child); + queue.push(child); + } + } + return first; +} + +function parseSpecialParameter(index, type, param) { + switch (type) { + case "Node": + return parseNode(param); + } + return null; +} diff --git a/src/debug/entry/javascript/problems/843.js b/src/debug/entry/javascript/problems/843.js new file mode 100644 index 0000000..283eb63 --- /dev/null +++ b/src/debug/entry/javascript/problems/843.js @@ -0,0 +1,25 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== 3) { + onParameterError(); + } + function Master(secret, wordlist) { + this.guess = function(word) { + if (!wordlist.includes(word)) { + return -1; + } + + let match = 0; + for (let i = 0; i < word.length; i++) { + if (word[i] === secret[i]) { + match += 1; + } + } + return match; + }; + } + userFunm(params[1], new Master(params[0], params[1])); +} + +function parseSpecialParameter(index, type, param) { + return null; +} diff --git a/src/debug/entry/javascript/problems/common.js b/src/debug/entry/javascript/problems/common.js new file mode 100644 index 0000000..b41768c --- /dev/null +++ b/src/debug/entry/javascript/problems/common.js @@ -0,0 +1,16 @@ +function runUserScript(userFunm, params, paramTypes) { + if (params.length !== paramTypes.length) { + onParameterError(); + } + + const parsedParams = params.map((param, index) => { + const type = paramTypes[index]; + return parseParameter(index, type, param); + }); + userFunm.apply(null, parsedParams); +} + + +function parseSpecialParameter(index, type, param) { + return null; +} diff --git a/src/debug/entry/python3/entry.py b/src/debug/entry/python3/entry.py new file mode 100644 index 0000000..84cd505 --- /dev/null +++ b/src/debug/entry/python3/entry.py @@ -0,0 +1,336 @@ +import importlib.util +import sys +from pathlib import Path +import json +import re +import socket +import codecs + +testString = str(sys.argv[2]) +funcName = str(sys.argv[3]) +paramTypes = str(sys.argv[4]).split(",") +problemNum = int(sys.argv[6]) +debugServerPort = int(sys.argv[7]) + + +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + + +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + + +def onParameterError(): + raise Exception( + "Parameters parsing error, please check the format of the input parameters") + + +def onParameterTypeError(t): + raise Exception("Unsupported parameter type: {}".format(t)) + + +def isNumber(num): + return isinstance(num, int) + + +def isString(s): + return isinstance(s, str) + + +def isCharacter(s): + return isString(s) and len(s) == 1 + + +def isList(li): + return isinstance(li, list) + + +def parseNumber(param): + if (not isNumber(param)): + onParameterError() + return param + + +def parseNumberArray(param): + if (not isList(param)): + onParameterError() + + for i in param: + if (not isNumber(i)): + onParameterError() + return param + + +def parseNumberArrayArray(param): + if (not isList(param)): + onParameterError() + for i in param: + parseNumberArray(i) + return param + + +def parseString(param): + if (not isString(param)): + onParameterError() + + return param + + +def parseStringArray(param): + if (not isList(param)): + onParameterError() + + for i in param: + parseString(i) + + return param + + +def parseStringArrayArray(param): + if (not isList(param)): + onParameterError() + + for i in param: + parseStringArray(i) + + return param + + +def parseListNode(param): + if (not isList(param)): + onParameterError() + + head = None + tail = None + + for i in param: + node = ListNode(i) + if (head == None): + tail = node + head = node + else: + tail.next = node + tail = node + + return head + + +def parseListNodeArray(param): + if (not isList(param)): + onParameterError() + + res = [] + for i in param: + res.append(parseListNode(i)) + + return res + + +def parseCharacter(param): + if (not isCharacter(param)): + onParameterError() + + return param + + +def parseCharacterArray(param): + if (not isList(param)): + onParameterError() + + for i in param: + parseCharacter(i) + + return param + + +def parseCharacterArrayArray(param): + if (not isList(param)): + onParameterError() + + for i in param: + parseCharacterArray(i) + + return param + + +class NestedInteger: + def __init__(self, ni): + nested = [] + if (isList(ni)): + for i, val in enumerate(ni): + nested.append(NestedInteger(val)) + self.nested = nested + self.ni = ni + + def isInteger(self) -> bool: + """ + @return True if this NestedInteger holds a single integer, rather than a nested list. + """ + if (isList(self.ni)): + return False + return True + + def getInteger(self) -> int: + """ + @return the single integer that this NestedInteger holds, if it holds a single integer + Return None if this NestedInteger holds a nested list + """ + if (isList(self.ni)): + return None + return self.ni + + def getList(self): + """ + @return the nested list that this NestedInteger holds, if it holds a nested list + Return None if this NestedInteger holds a single integer + """ + if (isList(self.ni)): + return self.nested + return None + + +def parseNestedIntegerArray(param): + arr = [] + for i, val in enumerate(param): + arr.append(NestedInteger(val)) + return arr + + +class MountainArray: + def __init__(self, param): + self.param = param + + def get(self, index: int) -> int: + return self.param[index] + + def length(self) -> int: + return len(self.param) + + +def parseMountainArray(param): + return MountainArray(param) + + +def parseTreeNode(param): + if (not isList(param)): + onParameterError() + + root = None + fifo = [] + i = 0 + while (i < len(param)): + if (i == 0): + root = TreeNode(param[i]) + i += 1 + fifo.append(root) + continue + + parent = fifo.pop(0) + if (param[i] != None): + left = TreeNode(param[i]) + parent.left = left + fifo.append(left) + + if (i + 1 < len(param) and param[i + 1] != None): + right = TreeNode(param[i + 1]) + parent.right = right + fifo.append(right) + + i = i + 2 + return root + + +def parseParameter(index, paramType, param): + switch = { + "number": lambda x: parseNumber(x), + "number[]": lambda x: parseNumberArray(x), + "number[][]": lambda x: parseNumberArrayArray(x), + "string": lambda x: parseString(x), + "string[]": lambda x: parseStringArray(x), + "string[][]": lambda x: parseStringArrayArray(x), + "ListNode": lambda x: parseListNode(x), + "ListNode[]": lambda x: parseListNodeArray(x), + "character": lambda x: parseCharacter(x), + "character[]": lambda x: parseCharacterArray(x), + "character[][]": lambda x: parseCharacterArrayArray(x), + "NestedInteger[]": lambda x: parseNestedIntegerArray(x), + "MountainArray": lambda x: parseMountainArray(x), + "TreeNode": lambda x: parseTreeNode(x), + } + switchfun = switch.get(paramType, 0) + + if switchfun is 0: + result = parseSpecialParameter(index, paramType, param) + if result is None: + onParameterTypeError(paramType) + return result + else: + return switchfun(param) + + +def loadModule(): + # add module to search path + parsedPath = Path(sys.argv[1]) + sys.path.append(parsedPath.parent) + + # load module + spec = importlib.util.spec_from_file_location(parsedPath.stem, sys.argv[1]) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +// @@stub-for-code@@ + + +def start(): + lines = testString.split("\\n") + params = [] + for i, val in enumerate(lines): + params.append(json.loads(codecs.getdecoder("unicode_escape")(val)[0])) + + module = loadModule() + + if (problemNum == 341): + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + + i, v = module.NestedIterator(newParams[0]), [] + while i.hasNext(): + v.append(i.next()) + else: + solution = module.Solution() + func = getattr(solution, funcName) + + runUserScript(func, params, paramTypes) + + +def makeMessage(ty, message): + return json.dumps({ + "type": ty, + "message": message, + "problemNum": problemNum, + "filePath": sys.argv[1], + "testString": testString, + "language": "python", + }).encode("utf-8") + + +if __name__ == "__main__": + sock = socket.socket() + sock.connect(("127.0.0.1", debugServerPort)) + try: + start() + sock.send(makeMessage("success", "")) + except Exception as identifier: + sock.send(makeMessage("error", str(identifier))) + raise identifier + finally: + sock.close() diff --git a/src/debug/entry/python3/problems/1095.py b/src/debug/entry/python3/problems/1095.py new file mode 100644 index 0000000..b7644ea --- /dev/null +++ b/src/debug/entry/python3/problems/1095.py @@ -0,0 +1,10 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + func(parseParameter(0, 'number', params[1]), parseParameter( + 1, 'MountainArray', params[0])) + + +def parseSpecialParameter(index, paramType, param): + return None diff --git a/src/debug/entry/python3/problems/116.py b/src/debug/entry/python3/problems/116.py new file mode 100644 index 0000000..bb95be5 --- /dev/null +++ b/src/debug/entry/python3/problems/116.py @@ -0,0 +1,37 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + func(*newParams) + + +class Node: + def __init__(self, val, left, right, next): + self.val = val + self.left = left + self.right = right + self.next = next + + +def parseNode(param): + arr = [] + + for i, val in enumerate(param): + node = Node(val, None, None, None) + arr.append(node) + if i is not 0: + if i % 2 is 1: + arr[int((i - 1) / 2)].left = node + else: + arr[int((i - 2) / 2)].right = node + + return arr[0] + + +def parseSpecialParameter(index, paramType, param): + if paramType == "Node": + return parseNode(param) + return None diff --git a/src/debug/entry/python3/problems/117.py b/src/debug/entry/python3/problems/117.py new file mode 100644 index 0000000..d4db266 --- /dev/null +++ b/src/debug/entry/python3/problems/117.py @@ -0,0 +1,46 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + func(*newParams) + + +class Node: + def __init__(self, val, left, right, next): + self.val = val + self.left = left + self.right = right + self.next = next + + +def parseNode(param): + first = Node(param[0], None, None, None) + arr = [] + arr.append([first, 0]) + + for i, val in enumerate(param): + if i is 0: + continue + + top = arr[0] + val = None if param[i] is None else Node(param[i], None, None, None) + if top[1] is 0: + top[0].left = val + top[1] = 1 + else: + top[0].right = val + arr.pop(0) + + if val is not None: + arr.append([val, 0]) + + return first + + +def parseSpecialParameter(index, paramType, param): + if paramType == "Node": + return parseNode(param) + return None diff --git a/src/debug/entry/python3/problems/133.py b/src/debug/entry/python3/problems/133.py new file mode 100644 index 0000000..0ae22a4 --- /dev/null +++ b/src/debug/entry/python3/problems/133.py @@ -0,0 +1,32 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + func(*newParams) + + +class Node: + def __init__(self, val, neighbors): + self.val = val + self.neighbors = neighbors + + +def parseNode(param, nodeMap): + arr = [] + for i, val in enumerate(param): + arr.append(Node(i + 1, [])) + + for i, val in enumerate(param): + for j, k in enumerate(val): + arr[i].neighbors.append(arr[k - 1]) + + return arr[0] + + +def parseSpecialParameter(index, paramType, param): + if paramType == "Node": + return parseNode(param, None) + return None diff --git a/src/debug/entry/python3/problems/138.py b/src/debug/entry/python3/problems/138.py new file mode 100644 index 0000000..559c6e6 --- /dev/null +++ b/src/debug/entry/python3/problems/138.py @@ -0,0 +1,36 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + func(*newParams) + + +class Node: + def __init__(self, val, next, random): + self.val = val + self.next = next + self.random = random + + +def parseNode(param, nodeMap): + arr = [] + for i, val in enumerate(param): + arr.append(Node(val[0], None, None)) + + for i, val in enumerate(param): + if i is not len(param) - 1: + arr[i].next = arr[i + 1] + + if val[1] is not None: + arr[i].random = arr[val[1]] + + return arr[0] + + +def parseSpecialParameter(index, paramType, param): + if paramType == "Node": + return parseNode(param, None) + return None diff --git a/src/debug/entry/python3/problems/278.py b/src/debug/entry/python3/problems/278.py new file mode 100644 index 0000000..057372b --- /dev/null +++ b/src/debug/entry/python3/problems/278.py @@ -0,0 +1,18 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != 2): + onParameterError() + + version = params[1] + n = params[0] + + def isBadVersion(k): + if k > version: + return True + return False + + newParams = [n] + func(*newParams) + + +def parseSpecialParameter(index, paramType, param): + return None diff --git a/src/debug/entry/python3/problems/429.py b/src/debug/entry/python3/problems/429.py new file mode 100644 index 0000000..cacc9d3 --- /dev/null +++ b/src/debug/entry/python3/problems/429.py @@ -0,0 +1,45 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + func(*newParams) + + +class Node: + def __init__(self, val, children): + self.val = val + self.children = children + + +def parseNode(param): + if len(param) is 0: + return + + first = Node(param[0], []) + arr = [first] + + for i, val in enumerate(param): + if i is 0: + continue + + if i is 1: + continue + + top = arr[0] + if val is None: + arr.pop(0) + else: + child = Node(val, []) + top.children.append(child) + arr.append(child) + + return first + + +def parseSpecialParameter(index, paramType, param): + if paramType == "Node": + return parseNode(param) + return None diff --git a/src/debug/entry/python3/problems/559.py b/src/debug/entry/python3/problems/559.py new file mode 100644 index 0000000..cacc9d3 --- /dev/null +++ b/src/debug/entry/python3/problems/559.py @@ -0,0 +1,45 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + func(*newParams) + + +class Node: + def __init__(self, val, children): + self.val = val + self.children = children + + +def parseNode(param): + if len(param) is 0: + return + + first = Node(param[0], []) + arr = [first] + + for i, val in enumerate(param): + if i is 0: + continue + + if i is 1: + continue + + top = arr[0] + if val is None: + arr.pop(0) + else: + child = Node(val, []) + top.children.append(child) + arr.append(child) + + return first + + +def parseSpecialParameter(index, paramType, param): + if paramType == "Node": + return parseNode(param) + return None diff --git a/src/debug/entry/python3/problems/589.py b/src/debug/entry/python3/problems/589.py new file mode 100644 index 0000000..cacc9d3 --- /dev/null +++ b/src/debug/entry/python3/problems/589.py @@ -0,0 +1,45 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + func(*newParams) + + +class Node: + def __init__(self, val, children): + self.val = val + self.children = children + + +def parseNode(param): + if len(param) is 0: + return + + first = Node(param[0], []) + arr = [first] + + for i, val in enumerate(param): + if i is 0: + continue + + if i is 1: + continue + + top = arr[0] + if val is None: + arr.pop(0) + else: + child = Node(val, []) + top.children.append(child) + arr.append(child) + + return first + + +def parseSpecialParameter(index, paramType, param): + if paramType == "Node": + return parseNode(param) + return None diff --git a/src/debug/entry/python3/problems/590.py b/src/debug/entry/python3/problems/590.py new file mode 100644 index 0000000..cacc9d3 --- /dev/null +++ b/src/debug/entry/python3/problems/590.py @@ -0,0 +1,45 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + func(*newParams) + + +class Node: + def __init__(self, val, children): + self.val = val + self.children = children + + +def parseNode(param): + if len(param) is 0: + return + + first = Node(param[0], []) + arr = [first] + + for i, val in enumerate(param): + if i is 0: + continue + + if i is 1: + continue + + top = arr[0] + if val is None: + arr.pop(0) + else: + child = Node(val, []) + top.children.append(child) + arr.append(child) + + return first + + +def parseSpecialParameter(index, paramType, param): + if paramType == "Node": + return parseNode(param) + return None diff --git a/src/debug/entry/python3/problems/843.py b/src/debug/entry/python3/problems/843.py new file mode 100644 index 0000000..ff4a35f --- /dev/null +++ b/src/debug/entry/python3/problems/843.py @@ -0,0 +1,29 @@ +class Master: + def __init__(self, secret, wordlist): + self.secret = secret + self.wordlist = wordlist + + def guess(self, word: str) -> int: + match = 0 + if word not in self.wordlist: + return -1 + for i, val in enumerate(word): + if (val == self.secret[i]): + match += 1 + + return match + + +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + + func(newParams[1], Master(newParams[0], newParams[1])) + + +def parseSpecialParameter(index, paramType, param): + return None diff --git a/src/debug/entry/python3/problems/common.py b/src/debug/entry/python3/problems/common.py new file mode 100644 index 0000000..2112df2 --- /dev/null +++ b/src/debug/entry/python3/problems/common.py @@ -0,0 +1,12 @@ +def runUserScript(func, params, paramTypes): + if (len(params) != len(paramTypes)): + onParameterError() + + newParams = [] + for i, val in enumerate(params): + newParams.append(parseParameter(i, paramTypes[i], val)) + func(*newParams) + + +def parseSpecialParameter(index, type, param): + return None diff --git a/src/debug/executor/cppExecutor.ts b/src/debug/executor/cppExecutor.ts new file mode 100644 index 0000000..8ab7f2d --- /dev/null +++ b/src/debug/executor/cppExecutor.ts @@ -0,0 +1,445 @@ +import * as fse from "fs-extra"; +import * as path from "path"; +import * as vscode from "vscode"; +import { logOutput } from "../../utils/OutputUtils"; + +import { executeCommand } from "../../utils/CliUtils"; +import { + fileMeta, + getEntryFile, + getProblemSpecialCode, + randomString, + extensionState, + IDebugConfig, + IProblemType, +} from "../../utils/problemUtils"; + +import problemTypes from "../../utils/problemTypes"; +import { isWindows } from "../../utils/SystemUtils"; + +function getGdbDefaultConfig(): IDebugConfig { + return { + type: "cppdbg", + MIMode: "gdb", + setupCommands: [ + { + description: "Enable pretty-printing for gdb", + text: "-enable-pretty-printing", + ignoreFailures: true, + }, + ], + miDebuggerPath: isWindows() ? "gdb.exe" : "gdb", + }; +} + +function getClangDefaultConfig(): IDebugConfig { + return { + type: "cppdbg", + MIMode: "lldb", + externalConsole: false, + }; +} + +const templateMap: any = { + 116: [117], + 429: [559, 589, 590], +}; + +function getTemplateId(id: string): string { + const findKey: string | undefined = Object.keys(templateMap).find((key: string) => { + const numId: number = parseInt(id, 10); + return templateMap[key].includes(numId); + }); + return findKey ? findKey : id; +} + +class CppExecutor { + public async execute( + filePath: string, + testString: string, + language: string, + port: number + ): Promise { + const sourceFileContent: string = (await fse.readFile(filePath)).toString(); + const meta: { id: string; lang: string } | null = fileMeta(sourceFileContent); + if (meta == null) { + vscode.window.showErrorMessage( + "File meta info has been changed, please check the content: '@lc app=leetcode.cn id=xx lang=xx'." + ); + return; + } + const problemType: IProblemType = problemTypes[meta.id]; + if (problemType == null) { + vscode.window.showErrorMessage(`Notsupported problem: ${meta.id}.`); + return; + } + + const program = await getEntryFile(meta.lang, meta.id); + + const newSourceFileName: string = `source${language}problem${meta.id}.cpp`; + const newSourceFilePath: string = path.join(extensionState.cachePath, newSourceFileName); + + const commonHeaderName: string = `common${language}problem${meta.id}.h`; + const commonImplementName: string = `common${language}problem${meta.id}.cpp`; + + // check whether module.exports is exist or not + const moduleExportsReg: RegExp = /\/\/ @before-stub-for-debug-begin/; + if (!moduleExportsReg.test(sourceFileContent)) { + const newContent: string = + `// @before-stub-for-debug-begin + + + + + +// @before-stub-for-debug-end\n\n` + sourceFileContent; + await fse.writeFile(filePath, newContent); + + // create source file for build because g++ does not support inlucde file with chinese name + await fse.writeFile(newSourceFilePath, newContent); + } else { + await fse.writeFile(newSourceFilePath, sourceFileContent); + } + + const params: string[] = testString.split("\\n"); + const paramsType: string[] = problemType.paramTypes; + if (params.length !== paramsType.length) { + vscode.window.showErrorMessage("Input parameters is not match the problem!"); + return; + } + + const templateId: string = getTemplateId(meta.id); + + const indent: string = " "; + let insertCode: string = `vector params{${params.map((p: string) => `"${p}"`).join(", ")}};\n`; + const callArgs: string[] = []; + paramsType.map((type: string, index: number) => { + callArgs.push(`arg${index}`); + + insertCode += ` + string param${index} = params[${index}]; + cJSON *item${index} = cJSON_Parse(param${index}.c_str()); +`; + switch (type) { + case "number": + insertCode += `${indent}int arg${index} = parseNumber(item${index});\n`; + break; + case "number[]": + insertCode += `${indent}vector arg${index} = parseNumberArray(item${index});\n`; + break; + case "number[][]": + insertCode += `${indent}vector> arg${index} = parseNumberArrayArray(item${index});\n`; + break; + case "string": + insertCode += `${indent}string arg${index} = parseString(item${index});\n`; + break; + case "string[]": + insertCode += `${indent}vector arg${index} = parseStringArray(item${index});\n`; + break; + case "string[][]": + insertCode += `${indent}vector> arg${index} = parseStringArrayArray(item${index});\n`; + break; + case "ListNode": + insertCode += `${indent}ListNode *arg${index} = parseListNode(parseNumberArray(item${index}));\n`; + break; + case "ListNode[]": + insertCode += `${indent}vector arg${index} = parseListNodeArray(parseNumberArrayArray(item${index}));\n`; + break; + case "character": + insertCode += `${indent}char arg${index} = parseCharacter(item${index});\n`; + break; + case "character[]": + insertCode += `${indent}vector arg${index} = parseCharacterArray(item${index});\n`; + break; + case "character[][]": + insertCode += `${indent}vector> arg${index} = parseCharacterArrayArray(item${index});\n`; + break; + case "NestedInteger[]": + insertCode += `${indent}vector arg${index} = parseNestedIntegerArray(item${index});\n`; + break; + case "MountainArray": + insertCode += `${indent}MountainArray arg${index} = MountainArray(parseNumberArray(item${index}));\n`; + break; + case "TreeNode": + insertCode += `${indent}TreeNode * arg${index} = parseTreeNode(item${index});\n`; + break; + case "Node": + if (templateId === "133") { + insertCode += `${indent}Node * arg${index} = parseNode(parseNumberArrayArray(item${index}));\n`; + } else if (templateId === "138") { + insertCode += `${indent}Node * arg${index} = parseNode(parsecJSONArray(item${index}));\n`; + } else { + insertCode += `${indent}Node * arg${index} = parseNode(item${index});\n`; + } + break; + } + }); + if (templateId === "278") { + insertCode += `${indent}badVersion = arg1;\n`; + insertCode += `${indent}(new Solution())->${problemType.funName}(arg0);\n`; + } else if (templateId === "341") { + insertCode += `${indent}NestedIterator i(arg0);\n`; + insertCode += `${indent}while (i.hasNext()) cout << i.next();;\n`; + } else if (templateId === "843") { + insertCode += `${indent}secret = arg0;\n`; + insertCode += `${indent}Master master;\n`; + insertCode += `${indent}(new Solution())->${problemType.funName}(arg1, master);\n`; + } else if (templateId === "1095") { + insertCode += `${indent}(new Solution())->${problemType.funName}(arg1, arg0);\n`; + } else { + insertCode += `${indent}(new Solution())->${problemType.funName}(${callArgs.join(", ")});\n`; + } + + // insert include code and replace function namem + const includeFileRegExp: RegExp = /\/\/ @@stub\-for\-include\-code@@/; + const codeRegExp: RegExp = /\/\/ @@stub\-for\-body\-code@@/; + const entryFile: string = program; + const entryFileContent: string = (await fse.readFile(entryFile)).toString(); + const newEntryFileContent: string = entryFileContent + .replace(includeFileRegExp, `#include "${commonHeaderName}"\n#include "${newSourceFileName}"`) + .replace(codeRegExp, insertCode); + await fse.writeFile(entryFile, newEntryFileContent); + + const extDir: string = vscode.extensions.getExtension("ccagml.vscode-leetcode-problem-rating")!.extensionPath; + + // copy common.h + const commonHeaderPath: string = path.join(extDir, "src/debug/entry/cpp/problems/common.h"); + const commonHeaderContent: string = (await fse.readFile(commonHeaderPath)).toString(); + const commonHeaderDestPath: string = path.join(extensionState.cachePath, commonHeaderName); + + const specialDefineCode: string = await getProblemSpecialCode(language, templateId, "h", extDir); + await fse.writeFile( + commonHeaderDestPath, + commonHeaderContent.replace(/\/\/ @@stub\-for\-problem\-define\-code@@/, specialDefineCode) + ); + + // copy common.cpp + const commonPath: string = path.join(extDir, "src/debug/entry/cpp/problems/common.cpp"); + const commonContent: string = (await fse.readFile(commonPath)) + .toString() + .replace(includeFileRegExp, `#include "${commonHeaderName}"`); + const commonDestPath: string = path.join(extensionState.cachePath, commonImplementName); + + const specialCode: string = await getProblemSpecialCode(language, templateId, "cpp", extDir); + await fse.writeFile( + commonDestPath, + commonContent.replace(/\/\/ @@stub\-for\-problem\-define\-code@@/, specialCode) + ); + + const exePath: string = path.join(extensionState.cachePath, `${language}problem${meta.id}.exe`); + const thirdPartyPath: string = path.join(extDir, "src/debug/thirdparty/c"); + const jsonPath: string = path.join(extDir, "src/debug/thirdparty/c/cJSON.c"); + + const compiler = vscode.workspace.getConfiguration("debug-leetcode").get("cppCompiler") ?? "gdb"; + let debugConfig: any; + if (compiler === "clang") { + debugConfig = await this.getClangDebugConfig({ + program, + exePath, + commonDestPath, + jsonPath, + thirdPartyPath, + filePath, + newSourceFilePath, + }); + } else { + debugConfig = await this.getGdbDebugConfig({ + program, + exePath, + commonDestPath, + jsonPath, + thirdPartyPath, + filePath, + newSourceFilePath, + }); + } + + if (debugConfig == null) { + return; + } + + const args: string[] = [ + filePath, + testString.replace(/\\"/g, '\\\\"'), + problemType.funName, + problemType.paramTypes.join(","), + problemType.returnType, + meta.id, + port.toString(), + ]; + const debugSessionName: string = randomString(16); + const debuging: boolean = await vscode.debug.startDebugging( + undefined, + Object.assign({}, debugConfig, { + request: "launch", + name: debugSessionName, + args, + }) + ); + + if (debuging) { + const debugSessionDisposes: vscode.Disposable[] = []; + + vscode.debug.breakpoints.map((bp: vscode.SourceBreakpoint) => { + if (bp.location.uri.fsPath === newSourceFilePath) { + vscode.debug.removeBreakpoints([bp]); + } + }); + + vscode.debug.breakpoints.map((bp: vscode.SourceBreakpoint) => { + if (bp.location.uri.fsPath === filePath) { + const location: vscode.Location = new vscode.Location(vscode.Uri.file(newSourceFilePath), bp.location.range); + vscode.debug.addBreakpoints([ + new vscode.SourceBreakpoint(location, bp.enabled, bp.condition, bp.hitCondition, bp.logMessage), + ]); + } + }); + + debugSessionDisposes.push( + vscode.debug.onDidChangeBreakpoints((event: vscode.BreakpointsChangeEvent) => { + event.added.map((bp: vscode.SourceBreakpoint) => { + if (bp.location.uri.fsPath === filePath) { + const location: vscode.Location = new vscode.Location( + vscode.Uri.file(newSourceFilePath), + bp.location.range + ); + vscode.debug.addBreakpoints([ + new vscode.SourceBreakpoint(location, bp.enabled, bp.condition, bp.hitCondition, bp.logMessage), + ]); + } + }); + + event.removed.map((bp: vscode.SourceBreakpoint) => { + if (bp.location.uri.fsPath === filePath) { + const location: vscode.Location = new vscode.Location( + vscode.Uri.file(newSourceFilePath), + bp.location.range + ); + vscode.debug.removeBreakpoints([new vscode.SourceBreakpoint(location)]); + } + }); + + event.changed.map((bp: vscode.SourceBreakpoint) => { + if (bp.location.uri.fsPath === filePath) { + const location: vscode.Location = new vscode.Location( + vscode.Uri.file(newSourceFilePath), + bp.location.range + ); + vscode.debug.removeBreakpoints([new vscode.SourceBreakpoint(location)]); + vscode.debug.addBreakpoints([ + new vscode.SourceBreakpoint(location, bp.enabled, bp.condition, bp.hitCondition, bp.logMessage), + ]); + } + }); + }) + ); + + debugSessionDisposes.push( + vscode.debug.onDidTerminateDebugSession((event: vscode.DebugSession) => { + if (event.name === debugSessionName) { + debugSessionDisposes.map((d: vscode.Disposable) => d.dispose()); + } + }) + ); + } + + return; + } + + private async getGdbDebugConfig({ + program, + exePath, + commonDestPath, + jsonPath, + thirdPartyPath, + filePath, + newSourceFilePath, + }: { + program: string; + exePath: string; + commonDestPath: string; + jsonPath: string; + thirdPartyPath: string; + filePath: string; + newSourceFilePath: string; + }) { + const debugConfig = getGdbDefaultConfig(); + try { + const includePath: string = path.dirname(exePath); + await executeCommand( + "g++", + ["-g", program, commonDestPath, jsonPath, "-o", exePath, "-I", includePath, "-I", thirdPartyPath], + { shell: false } + ); + } catch (e) { + vscode.window.showErrorMessage(e); + logOutput.append(e.stack); + logOutput.show(); + return; + } + + debugConfig.program = exePath; + debugConfig.cwd = extensionState.cachePath; + // map build source file to user source file + debugConfig.sourceFileMap = { + [newSourceFilePath]: filePath, + }; + return debugConfig; + } + + private async getClangDebugConfig({ + program, + exePath, + commonDestPath, + jsonPath, + thirdPartyPath, + filePath, + newSourceFilePath, + }: { + program: string; + exePath: string; + commonDestPath: string; + jsonPath: string; + thirdPartyPath: string; + filePath: string; + newSourceFilePath: string; + }) { + const debugConfig = getClangDefaultConfig(); + try { + const includePath: string = path.dirname(exePath); + await executeCommand( + "/usr/bin/clang++", + [ + "-std=c++17", + "-stdlib=libc++", + "-g", + program, + commonDestPath, + jsonPath, + "-o", + exePath, + "-I", + includePath, + "-I", + thirdPartyPath, + ], + { shell: false } + ); + } catch (e) { + vscode.window.showErrorMessage(e); + logOutput.append(e.stack); + logOutput.show(); + return; + } + + debugConfig.program = exePath; + debugConfig.cwd = extensionState.cachePath; + // map build source file to user source file + debugConfig.sourceFileMap = { + [newSourceFilePath]: filePath, + }; + return debugConfig; + } +} + +export const cppExecutor: CppExecutor = new CppExecutor(); diff --git a/src/debug/thirdparty/c/cJSON.c b/src/debug/thirdparty/c/cJSON.c new file mode 100644 index 0000000..713334c --- /dev/null +++ b/src/debug/thirdparty/c/cJSON.c @@ -0,0 +1,2979 @@ +/* + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +/* cJSON */ +/* JSON parser in C. */ + +/* disable warnings about old C89 functions in MSVC */ +#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +#define _CRT_SECURE_NO_DEPRECATE +#endif + +#ifdef __GNUC__ +#pragma GCC visibility push(default) +#endif +#if defined(_MSC_VER) +#pragma warning (push) +/* disable warning about single line comments in system headers */ +#pragma warning (disable : 4001) +#endif + +#include +#include +#include +#include +#include +#include + +#ifdef ENABLE_LOCALES +#include +#endif + +#if defined(_MSC_VER) +#pragma warning (pop) +#endif +#ifdef __GNUC__ +#pragma GCC visibility pop +#endif + +#include "cJSON.h" + +/* define our own boolean type */ +#ifdef true +#undef true +#endif +#define true ((cJSON_bool)1) + +#ifdef false +#undef false +#endif +#define false ((cJSON_bool)0) + +typedef struct { + const unsigned char *json; + size_t position; +} error; +static error global_error = { NULL, 0 }; + +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) +{ + return (const char*) (global_error.json + global_error.position); +} + +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) { + if (!cJSON_IsString(item)) { + return NULL; + } + + return item->valuestring; +} + +/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ +#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 12) + #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. +#endif + +CJSON_PUBLIC(const char*) cJSON_Version(void) +{ + static char version[15]; + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); + + return version; +} + +/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ +static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) +{ + if ((string1 == NULL) || (string2 == NULL)) + { + return 1; + } + + if (string1 == string2) + { + return 0; + } + + for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + { + if (*string1 == '\0') + { + return 0; + } + } + + return tolower(*string1) - tolower(*string2); +} + +typedef struct internal_hooks +{ + void *(CJSON_CDECL *allocate)(size_t size); + void (CJSON_CDECL *deallocate)(void *pointer); + void *(CJSON_CDECL *reallocate)(void *pointer, size_t size); +} internal_hooks; + +#if defined(_MSC_VER) +/* work around MSVC error C2322: '...' address of dllimport '...' is not static */ +static void * CJSON_CDECL internal_malloc(size_t size) +{ + return malloc(size); +} +static void CJSON_CDECL internal_free(void *pointer) +{ + free(pointer); +} +static void * CJSON_CDECL internal_realloc(void *pointer, size_t size) +{ + return realloc(pointer, size); +} +#else +#define internal_malloc malloc +#define internal_free free +#define internal_realloc realloc +#endif + +/* strlen of character literals resolved at compile time */ +#define static_strlen(string_literal) (sizeof(string_literal) - sizeof("")) + +static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; + +static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) +{ + size_t length = 0; + unsigned char *copy = NULL; + + if (string == NULL) + { + return NULL; + } + + length = strlen((const char*)string) + sizeof(""); + copy = (unsigned char*)hooks->allocate(length); + if (copy == NULL) + { + return NULL; + } + memcpy(copy, string, length); + + return copy; +} + +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) +{ + if (hooks == NULL) + { + /* Reset hooks */ + global_hooks.allocate = malloc; + global_hooks.deallocate = free; + global_hooks.reallocate = realloc; + return; + } + + global_hooks.allocate = malloc; + if (hooks->malloc_fn != NULL) + { + global_hooks.allocate = hooks->malloc_fn; + } + + global_hooks.deallocate = free; + if (hooks->free_fn != NULL) + { + global_hooks.deallocate = hooks->free_fn; + } + + /* use realloc only if both free and malloc are used */ + global_hooks.reallocate = NULL; + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) + { + global_hooks.reallocate = realloc; + } +} + +/* Internal constructor. */ +static cJSON *cJSON_New_Item(const internal_hooks * const hooks) +{ + cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); + if (node) + { + memset(node, '\0', sizeof(cJSON)); + } + + return node; +} + +/* Delete a cJSON structure. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) +{ + cJSON *next = NULL; + while (item != NULL) + { + next = item->next; + if (!(item->type & cJSON_IsReference) && (item->child != NULL)) + { + cJSON_Delete(item->child); + } + if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) + { + global_hooks.deallocate(item->valuestring); + } + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + global_hooks.deallocate(item->string); + } + global_hooks.deallocate(item); + item = next; + } +} + +/* get the decimal point character of the current locale */ +static unsigned char get_decimal_point(void) +{ +#ifdef ENABLE_LOCALES + struct lconv *lconv = localeconv(); + return (unsigned char) lconv->decimal_point[0]; +#else + return '.'; +#endif +} + +typedef struct +{ + const unsigned char *content; + size_t length; + size_t offset; + size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ + internal_hooks hooks; +} parse_buffer; + +/* check if the given size is left to read in a given parse buffer (starting with 1) */ +#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) +/* check if the buffer can be accessed at the given index (starting with 0) */ +#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) +#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) +/* get a pointer to the buffer at the position */ +#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) + +/* Parse the input text to generate a number, and populate the result into item. */ +static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) +{ + double number = 0; + unsigned char *after_end = NULL; + unsigned char number_c_string[64]; + unsigned char decimal_point = get_decimal_point(); + size_t i = 0; + + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; + } + + /* copy the number into a temporary buffer and replace '.' with the decimal point + * of the current locale (for strtod) + * This also takes care of '\0' not necessarily being available for marking the end of the input */ + for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) + { + switch (buffer_at_offset(input_buffer)[i]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '+': + case '-': + case 'e': + case 'E': + number_c_string[i] = buffer_at_offset(input_buffer)[i]; + break; + + case '.': + number_c_string[i] = decimal_point; + break; + + default: + goto loop_end; + } + } +loop_end: + number_c_string[i] = '\0'; + + number = strtod((const char*)number_c_string, (char**)&after_end); + if (number_c_string == after_end) + { + return false; /* parse_error */ + } + + item->valuedouble = number; + + /* use saturation in case of overflow */ + if (number >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (number <= (double)INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)number; + } + + item->type = cJSON_Number; + + input_buffer->offset += (size_t)(after_end - number_c_string); + return true; +} + +/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) +{ + if (number >= INT_MAX) + { + object->valueint = INT_MAX; + } + else if (number <= (double)INT_MIN) + { + object->valueint = INT_MIN; + } + else + { + object->valueint = (int)number; + } + + return object->valuedouble = number; +} + +typedef struct +{ + unsigned char *buffer; + size_t length; + size_t offset; + size_t depth; /* current nesting depth (for formatted printing) */ + cJSON_bool noalloc; + cJSON_bool format; /* is this print a formatted print */ + internal_hooks hooks; +} printbuffer; + +/* realloc printbuffer if necessary to have at least "needed" bytes more */ +static unsigned char* ensure(printbuffer * const p, size_t needed) +{ + unsigned char *newbuffer = NULL; + size_t newsize = 0; + + if ((p == NULL) || (p->buffer == NULL)) + { + return NULL; + } + + if ((p->length > 0) && (p->offset >= p->length)) + { + /* make sure that offset is valid */ + return NULL; + } + + if (needed > INT_MAX) + { + /* sizes bigger than INT_MAX are currently not supported */ + return NULL; + } + + needed += p->offset + 1; + if (needed <= p->length) + { + return p->buffer + p->offset; + } + + if (p->noalloc) { + return NULL; + } + + /* calculate new buffer size */ + if (needed > (INT_MAX / 2)) + { + /* overflow of int, use INT_MAX if possible */ + if (needed <= INT_MAX) + { + newsize = INT_MAX; + } + else + { + return NULL; + } + } + else + { + newsize = needed * 2; + } + + if (p->hooks.reallocate != NULL) + { + /* reallocate with realloc if available */ + newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); + if (newbuffer == NULL) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + } + else + { + /* otherwise reallocate manually */ + newbuffer = (unsigned char*)p->hooks.allocate(newsize); + if (!newbuffer) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + if (newbuffer) + { + memcpy(newbuffer, p->buffer, p->offset + 1); + } + p->hooks.deallocate(p->buffer); + } + p->length = newsize; + p->buffer = newbuffer; + + return newbuffer + p->offset; +} + +/* calculate the new length of the string in a printbuffer and update the offset */ +static void update_offset(printbuffer * const buffer) +{ + const unsigned char *buffer_pointer = NULL; + if ((buffer == NULL) || (buffer->buffer == NULL)) + { + return; + } + buffer_pointer = buffer->buffer + buffer->offset; + + buffer->offset += strlen((const char*)buffer_pointer); +} + +/* securely comparison of floating-point variables */ +static cJSON_bool compare_double(double a, double b) +{ + return (fabs(a - b) <= CJSON_DOUBLE_PRECISION); +} + +/* Render the number nicely from the given item into a string. */ +static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + double d = item->valuedouble; + int length = 0; + size_t i = 0; + unsigned char number_buffer[26] = {0}; /* temporary buffer to print the number into */ + unsigned char decimal_point = get_decimal_point(); + double test = 0.0; + + if (output_buffer == NULL) + { + return false; + } + + /* This checks for NaN and Infinity */ + if ((d * 0) != 0) + { + length = sprintf((char*)number_buffer, "null"); + } + else + { + /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ + length = sprintf((char*)number_buffer, "%1.15g", d); + + /* Check whether the original double can be recovered */ + if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d)) + { + /* If not, print with 17 decimal places of precision */ + length = sprintf((char*)number_buffer, "%1.17g", d); + } + } + + /* sprintf failed or buffer overrun occurred */ + if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) + { + return false; + } + + /* reserve appropriate space in the output */ + output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); + if (output_pointer == NULL) + { + return false; + } + + /* copy the printed number to the output and replace locale + * dependent decimal point with '.' */ + for (i = 0; i < ((size_t)length); i++) + { + if (number_buffer[i] == decimal_point) + { + output_pointer[i] = '.'; + continue; + } + + output_pointer[i] = number_buffer[i]; + } + output_pointer[i] = '\0'; + + output_buffer->offset += (size_t)length; + + return true; +} + +/* parse 4 digit hexadecimal number */ +static unsigned parse_hex4(const unsigned char * const input) +{ + unsigned int h = 0; + size_t i = 0; + + for (i = 0; i < 4; i++) + { + /* parse digit */ + if ((input[i] >= '0') && (input[i] <= '9')) + { + h += (unsigned int) input[i] - '0'; + } + else if ((input[i] >= 'A') && (input[i] <= 'F')) + { + h += (unsigned int) 10 + input[i] - 'A'; + } + else if ((input[i] >= 'a') && (input[i] <= 'f')) + { + h += (unsigned int) 10 + input[i] - 'a'; + } + else /* invalid */ + { + return 0; + } + + if (i < 3) + { + /* shift left to make place for the next nibble */ + h = h << 4; + } + } + + return h; +} + +/* converts a UTF-16 literal to UTF-8 + * A literal can be one or two sequences of the form \uXXXX */ +static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) +{ + long unsigned int codepoint = 0; + unsigned int first_code = 0; + const unsigned char *first_sequence = input_pointer; + unsigned char utf8_length = 0; + unsigned char utf8_position = 0; + unsigned char sequence_length = 0; + unsigned char first_byte_mark = 0; + + if ((input_end - first_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + /* get the first utf16 sequence */ + first_code = parse_hex4(first_sequence + 2); + + /* check that the code is valid */ + if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) + { + goto fail; + } + + /* UTF16 surrogate pair */ + if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) + { + const unsigned char *second_sequence = first_sequence + 6; + unsigned int second_code = 0; + sequence_length = 12; /* \uXXXX\uXXXX */ + + if ((input_end - second_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) + { + /* missing second half of the surrogate pair */ + goto fail; + } + + /* get the second utf16 sequence */ + second_code = parse_hex4(second_sequence + 2); + /* check that the code is valid */ + if ((second_code < 0xDC00) || (second_code > 0xDFFF)) + { + /* invalid second half of the surrogate pair */ + goto fail; + } + + + /* calculate the unicode codepoint from the surrogate pair */ + codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); + } + else + { + sequence_length = 6; /* \uXXXX */ + codepoint = first_code; + } + + /* encode as UTF-8 + * takes at maximum 4 bytes to encode: + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + if (codepoint < 0x80) + { + /* normal ascii, encoding 0xxxxxxx */ + utf8_length = 1; + } + else if (codepoint < 0x800) + { + /* two bytes, encoding 110xxxxx 10xxxxxx */ + utf8_length = 2; + first_byte_mark = 0xC0; /* 11000000 */ + } + else if (codepoint < 0x10000) + { + /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ + utf8_length = 3; + first_byte_mark = 0xE0; /* 11100000 */ + } + else if (codepoint <= 0x10FFFF) + { + /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + utf8_length = 4; + first_byte_mark = 0xF0; /* 11110000 */ + } + else + { + /* invalid unicode codepoint */ + goto fail; + } + + /* encode as utf8 */ + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) + { + /* 10xxxxxx */ + (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); + codepoint >>= 6; + } + /* encode first byte */ + if (utf8_length > 1) + { + (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); + } + else + { + (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); + } + + *output_pointer += utf8_length; + + return sequence_length; + +fail: + return 0; +} + +/* Parse the input text into an unescaped cinput, and populate item. */ +static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) +{ + const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; + const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; + unsigned char *output_pointer = NULL; + unsigned char *output = NULL; + + /* not a string */ + if (buffer_at_offset(input_buffer)[0] != '\"') + { + goto fail; + } + + { + /* calculate approximate size of the output (overestimate) */ + size_t allocation_length = 0; + size_t skipped_bytes = 0; + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) + { + /* is escape sequence */ + if (input_end[0] == '\\') + { + if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) + { + /* prevent buffer overflow when last input character is a backslash */ + goto fail; + } + skipped_bytes++; + input_end++; + } + input_end++; + } + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) + { + goto fail; /* string ended unexpectedly */ + } + + /* This is at most how much we need for the output */ + allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; + output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); + if (output == NULL) + { + goto fail; /* allocation failure */ + } + } + + output_pointer = output; + /* loop through the string literal */ + while (input_pointer < input_end) + { + if (*input_pointer != '\\') + { + *output_pointer++ = *input_pointer++; + } + /* escape sequence */ + else + { + unsigned char sequence_length = 2; + if ((input_end - input_pointer) < 1) + { + goto fail; + } + + switch (input_pointer[1]) + { + case 'b': + *output_pointer++ = '\b'; + break; + case 'f': + *output_pointer++ = '\f'; + break; + case 'n': + *output_pointer++ = '\n'; + break; + case 'r': + *output_pointer++ = '\r'; + break; + case 't': + *output_pointer++ = '\t'; + break; + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; + + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ + goto fail; + } + break; + + default: + goto fail; + } + input_pointer += sequence_length; + } + } + + /* zero terminate the output */ + *output_pointer = '\0'; + + item->type = cJSON_String; + item->valuestring = (char*)output; + + input_buffer->offset = (size_t) (input_end - input_buffer->content); + input_buffer->offset++; + + return true; + +fail: + if (output != NULL) + { + input_buffer->hooks.deallocate(output); + } + + if (input_pointer != NULL) + { + input_buffer->offset = (size_t)(input_pointer - input_buffer->content); + } + + return false; +} + +/* Render the cstring provided to an escaped version that can be printed. */ +static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) +{ + const unsigned char *input_pointer = NULL; + unsigned char *output = NULL; + unsigned char *output_pointer = NULL; + size_t output_length = 0; + /* numbers of additional characters needed for escaping */ + size_t escape_characters = 0; + + if (output_buffer == NULL) + { + return false; + } + + /* empty string */ + if (input == NULL) + { + output = ensure(output_buffer, sizeof("\"\"")); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "\"\""); + + return true; + } + + /* set "flag" to 1 if something needs to be escaped */ + for (input_pointer = input; *input_pointer; input_pointer++) + { + switch (*input_pointer) + { + case '\"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + /* one character escape sequence */ + escape_characters++; + break; + default: + if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + break; + } + } + output_length = (size_t)(input_pointer - input) + escape_characters; + + output = ensure(output_buffer, output_length + sizeof("\"\"")); + if (output == NULL) + { + return false; + } + + /* no characters have to be escaped */ + if (escape_characters == 0) + { + output[0] = '\"'; + memcpy(output + 1, input, output_length); + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; + } + + output[0] = '\"'; + output_pointer = output + 1; + /* copy the string */ + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) + { + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) + { + /* normal character, copy */ + *output_pointer = *input_pointer; + } + else + { + /* character needs to be escaped */ + *output_pointer++ = '\\'; + switch (*input_pointer) + { + case '\\': + *output_pointer = '\\'; + break; + case '\"': + *output_pointer = '\"'; + break; + case '\b': + *output_pointer = 'b'; + break; + case '\f': + *output_pointer = 'f'; + break; + case '\n': + *output_pointer = 'n'; + break; + case '\r': + *output_pointer = 'r'; + break; + case '\t': + *output_pointer = 't'; + break; + default: + /* escape and print as unicode codepoint */ + sprintf((char*)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; + } + } + } + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; +} + +/* Invoke print_string_ptr (which is useful) on an item. */ +static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) +{ + return print_string_ptr((unsigned char*)item->valuestring, p); +} + +/* Predeclare these prototypes. */ +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); + +/* Utility to jump whitespace and cr/lf */ +static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL)) + { + return NULL; + } + + while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) + { + buffer->offset++; + } + + if (buffer->offset == buffer->length) + { + buffer->offset--; + } + + return buffer; +} + +/* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ +static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) + { + return NULL; + } + + if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) + { + buffer->offset += 3; + } + + return buffer; +} + +/* Parse an object - create a new root, and populate. */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; + cJSON *item = NULL; + + /* reset error position */ + global_error.json = NULL; + global_error.position = 0; + + if (value == NULL) + { + goto fail; + } + + buffer.content = (const unsigned char*)value; + buffer.length = strlen((const char*)value) + sizeof(""); + buffer.offset = 0; + buffer.hooks = global_hooks; + + item = cJSON_New_Item(&global_hooks); + if (item == NULL) /* memory fail */ + { + goto fail; + } + + if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) + { + /* parse failure. ep is set. */ + goto fail; + } + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) + { + buffer_skip_whitespace(&buffer); + if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') + { + goto fail; + } + } + if (return_parse_end) + { + *return_parse_end = (const char*)buffer_at_offset(&buffer); + } + + return item; + +fail: + if (item != NULL) + { + cJSON_Delete(item); + } + + if (value != NULL) + { + error local_error; + local_error.json = (const unsigned char*)value; + local_error.position = 0; + + if (buffer.offset < buffer.length) + { + local_error.position = buffer.offset; + } + else if (buffer.length > 0) + { + local_error.position = buffer.length - 1; + } + + if (return_parse_end != NULL) + { + *return_parse_end = (const char*)local_error.json + local_error.position; + } + + global_error = local_error; + } + + return NULL; +} + +/* Default options for cJSON_Parse */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) +{ + return cJSON_ParseWithOpts(value, 0, 0); +} + +#define cjson_min(a, b) ((a < b) ? a : b) + +static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) +{ + static const size_t default_buffer_size = 256; + printbuffer buffer[1]; + unsigned char *printed = NULL; + + memset(buffer, 0, sizeof(buffer)); + + /* create buffer */ + buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); + buffer->length = default_buffer_size; + buffer->format = format; + buffer->hooks = *hooks; + if (buffer->buffer == NULL) + { + goto fail; + } + + /* print the value */ + if (!print_value(item, buffer)) + { + goto fail; + } + update_offset(buffer); + + /* check if reallocate is available */ + if (hooks->reallocate != NULL) + { + printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); + if (printed == NULL) { + goto fail; + } + buffer->buffer = NULL; + } + else /* otherwise copy the JSON over to a new buffer */ + { + printed = (unsigned char*) hooks->allocate(buffer->offset + 1); + if (printed == NULL) + { + goto fail; + } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); + printed[buffer->offset] = '\0'; /* just to be sure */ + + /* free the buffer */ + hooks->deallocate(buffer->buffer); + } + + return printed; + +fail: + if (buffer->buffer != NULL) + { + hooks->deallocate(buffer->buffer); + } + + if (printed != NULL) + { + hooks->deallocate(printed); + } + + return NULL; +} + +/* Render a cJSON item/entity/structure to text. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) +{ + return (char*)print(item, true, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) +{ + return (char*)print(item, false, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; + + if (prebuffer < 0) + { + return NULL; + } + + p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) + { + return NULL; + } + + p.length = (size_t)prebuffer; + p.offset = 0; + p.noalloc = false; + p.format = fmt; + p.hooks = global_hooks; + + if (!print_value(item, &p)) + { + global_hooks.deallocate(p.buffer); + return NULL; + } + + return (char*)p.buffer; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; + + if ((length < 0) || (buffer == NULL)) + { + return false; + } + + p.buffer = (unsigned char*)buffer; + p.length = (size_t)length; + p.offset = 0; + p.noalloc = true; + p.format = format; + p.hooks = global_hooks; + + return print_value(item, &p); +} + +/* Parser core - when encountering text, process appropriately. */ +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) +{ + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; /* no input */ + } + + /* parse the different types of values */ + /* null */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) + { + item->type = cJSON_NULL; + input_buffer->offset += 4; + return true; + } + /* false */ + if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) + { + item->type = cJSON_False; + input_buffer->offset += 5; + return true; + } + /* true */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) + { + item->type = cJSON_True; + item->valueint = 1; + input_buffer->offset += 4; + return true; + } + /* string */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) + { + return parse_string(item, input_buffer); + } + /* number */ + if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) + { + return parse_number(item, input_buffer); + } + /* array */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) + { + return parse_array(item, input_buffer); + } + /* object */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) + { + return parse_object(item, input_buffer); + } + + return false; +} + +/* Render a value to text. */ +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output = NULL; + + if ((item == NULL) || (output_buffer == NULL)) + { + return false; + } + + switch ((item->type) & 0xFF) + { + case cJSON_NULL: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "null"); + return true; + + case cJSON_False: + output = ensure(output_buffer, 6); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer); + + case cJSON_Raw: + { + size_t raw_length = 0; + if (item->valuestring == NULL) + { + return false; + } + + raw_length = strlen(item->valuestring) + sizeof(""); + output = ensure(output_buffer, raw_length); + if (output == NULL) + { + return false; + } + memcpy(output, item->valuestring, raw_length); + return true; + } + + case cJSON_String: + return print_string(item, output_buffer); + + case cJSON_Array: + return print_array(item, output_buffer); + + case cJSON_Object: + return print_object(item, output_buffer); + + default: + return false; + } +} + +/* Build an array from input text. */ +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* head of the linked list */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (buffer_at_offset(input_buffer)[0] != '[') + { + /* not an array */ + goto fail; + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) + { + /* empty array */ + goto success; + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse next value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') + { + goto fail; /* expected end of array */ + } + +success: + input_buffer->depth--; + + item->type = cJSON_Array; + item->child = head; + + input_buffer->offset++; + + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; +} + +/* Render an array to text */ +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_element = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output array. */ + /* opening square bracket */ + output_pointer = ensure(output_buffer, 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer = '['; + output_buffer->offset++; + output_buffer->depth++; + + while (current_element != NULL) + { + if (!print_value(current_element, output_buffer)) + { + return false; + } + update_offset(output_buffer); + if (current_element->next) + { + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ','; + if(output_buffer->format) + { + *output_pointer++ = ' '; + } + *output_pointer = '\0'; + output_buffer->offset += length; + } + current_element = current_element->next; + } + + output_pointer = ensure(output_buffer, 2); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ']'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; +} + +/* Build an object from the text. */ +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* linked list head */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) + { + goto fail; /* not an object */ + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) + { + goto success; /* empty object */ + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse the name of the child */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_string(current_item, input_buffer)) + { + goto fail; /* failed to parse name */ + } + buffer_skip_whitespace(input_buffer); + + /* swap valuestring and string, because we parsed the name */ + current_item->string = current_item->valuestring; + current_item->valuestring = NULL; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) + { + goto fail; /* invalid object */ + } + + /* parse the value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) + { + goto fail; /* expected end of object */ + } + +success: + input_buffer->depth--; + + item->type = cJSON_Object; + item->child = head; + + input_buffer->offset++; + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; +} + +/* Render an object to text. */ +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_item = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output: */ + length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer++ = '{'; + output_buffer->depth++; + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + output_buffer->offset += length; + + while (current_item) + { + if (output_buffer->format) + { + size_t i; + output_pointer = ensure(output_buffer, output_buffer->depth); + if (output_pointer == NULL) + { + return false; + } + for (i = 0; i < output_buffer->depth; i++) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += output_buffer->depth; + } + + /* print key */ + if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ':'; + if (output_buffer->format) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += length; + + /* print value */ + if (!print_value(current_item, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + /* print comma if not last */ + length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0)); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + if (current_item->next) + { + *output_pointer++ = ','; + } + + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + *output_pointer = '\0'; + output_buffer->offset += length; + + current_item = current_item->next; + } + + output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); + if (output_pointer == NULL) + { + return false; + } + if (output_buffer->format) + { + size_t i; + for (i = 0; i < (output_buffer->depth - 1); i++) + { + *output_pointer++ = '\t'; + } + } + *output_pointer++ = '}'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; +} + +/* Get Array size/item / object item. */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) +{ + cJSON *child = NULL; + size_t size = 0; + + if (array == NULL) + { + return 0; + } + + child = array->child; + + while(child != NULL) + { + size++; + child = child->next; + } + + /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ + + return (int)size; +} + +static cJSON* get_array_item(const cJSON *array, size_t index) +{ + cJSON *current_child = NULL; + + if (array == NULL) + { + return NULL; + } + + current_child = array->child; + while ((current_child != NULL) && (index > 0)) + { + index--; + current_child = current_child->next; + } + + return current_child; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) +{ + if (index < 0) + { + return NULL; + } + + return get_array_item(array, (size_t)index); +} + +static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) +{ + cJSON *current_element = NULL; + + if ((object == NULL) || (name == NULL)) + { + return NULL; + } + + current_element = object->child; + if (case_sensitive) + { + while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0)) + { + current_element = current_element->next; + } + } + else + { + while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) + { + current_element = current_element->next; + } + } + + if ((current_element == NULL) || (current_element->string == NULL)) { + return NULL; + } + + return current_element; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, false); +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, true); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) +{ + return cJSON_GetObjectItem(object, string) ? 1 : 0; +} + +/* Utility for array list handling. */ +static void suffix_object(cJSON *prev, cJSON *item) +{ + prev->next = item; + item->prev = prev; +} + +/* Utility for handling references. */ +static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) +{ + cJSON *reference = NULL; + if (item == NULL) + { + return NULL; + } + + reference = cJSON_New_Item(hooks); + if (reference == NULL) + { + return NULL; + } + + memcpy(reference, item, sizeof(cJSON)); + reference->string = NULL; + reference->type |= cJSON_IsReference; + reference->next = reference->prev = NULL; + return reference; +} + +static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) +{ + cJSON *child = NULL; + + if ((item == NULL) || (array == NULL)) + { + return false; + } + + child = array->child; + + if (child == NULL) + { + /* list is empty, start new one */ + array->child = item; + } + else + { + /* append to the end */ + while (child->next) + { + child = child->next; + } + suffix_object(child, item); + } + + return true; +} + +/* Add item to array/object. */ +CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item) +{ + add_item_to_array(array, item); +} + +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic push +#endif +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wcast-qual" +#endif +/* helper function to cast away const */ +static void* cast_away_const(const void* string) +{ + return (void*)string; +} +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic pop +#endif + + +static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) +{ + char *new_key = NULL; + int new_type = cJSON_Invalid; + + if ((object == NULL) || (string == NULL) || (item == NULL)) + { + return false; + } + + if (constant_key) + { + new_key = (char*)cast_away_const(string); + new_type = item->type | cJSON_StringIsConst; + } + else + { + new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); + if (new_key == NULL) + { + return false; + } + + new_type = item->type & ~cJSON_StringIsConst; + } + + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + hooks->deallocate(item->string); + } + + item->string = new_key; + item->type = new_type; + + return add_item_to_array(object, item); +} + +CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +{ + add_item_to_object(object, string, item, &global_hooks, false); +} + +/* Add an item to an object with constant string as key */ +CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) +{ + add_item_to_object(object, string, item, &global_hooks, true); +} + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) +{ + if (array == NULL) + { + return; + } + + add_item_to_array(array, create_reference(item, &global_hooks)); +} + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) +{ + if ((object == NULL) || (string == NULL)) + { + return; + } + + add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); +} + +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) +{ + cJSON *null = cJSON_CreateNull(); + if (add_item_to_object(object, name, null, &global_hooks, false)) + { + return null; + } + + cJSON_Delete(null); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) +{ + cJSON *true_item = cJSON_CreateTrue(); + if (add_item_to_object(object, name, true_item, &global_hooks, false)) + { + return true_item; + } + + cJSON_Delete(true_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) +{ + cJSON *false_item = cJSON_CreateFalse(); + if (add_item_to_object(object, name, false_item, &global_hooks, false)) + { + return false_item; + } + + cJSON_Delete(false_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) +{ + cJSON *bool_item = cJSON_CreateBool(boolean); + if (add_item_to_object(object, name, bool_item, &global_hooks, false)) + { + return bool_item; + } + + cJSON_Delete(bool_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) +{ + cJSON *number_item = cJSON_CreateNumber(number); + if (add_item_to_object(object, name, number_item, &global_hooks, false)) + { + return number_item; + } + + cJSON_Delete(number_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) +{ + cJSON *string_item = cJSON_CreateString(string); + if (add_item_to_object(object, name, string_item, &global_hooks, false)) + { + return string_item; + } + + cJSON_Delete(string_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) +{ + cJSON *raw_item = cJSON_CreateRaw(raw); + if (add_item_to_object(object, name, raw_item, &global_hooks, false)) + { + return raw_item; + } + + cJSON_Delete(raw_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) +{ + cJSON *object_item = cJSON_CreateObject(); + if (add_item_to_object(object, name, object_item, &global_hooks, false)) + { + return object_item; + } + + cJSON_Delete(object_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) +{ + cJSON *array = cJSON_CreateArray(); + if (add_item_to_object(object, name, array, &global_hooks, false)) + { + return array; + } + + cJSON_Delete(array); + return NULL; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) +{ + if ((parent == NULL) || (item == NULL)) + { + return NULL; + } + + if (item->prev != NULL) + { + /* not the first element */ + item->prev->next = item->next; + } + if (item->next != NULL) + { + /* not the last element */ + item->next->prev = item->prev; + } + + if (item == parent->child) + { + /* first element */ + parent->child = item->next; + } + /* make sure the detached item doesn't point anywhere anymore */ + item->prev = NULL; + item->next = NULL; + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) +{ + if (which < 0) + { + return NULL; + } + + return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) +{ + cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItem(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); +} + +/* Replace array/object items with new ones. */ +CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) +{ + cJSON *after_inserted = NULL; + + if (which < 0) + { + return; + } + + after_inserted = get_array_item(array, (size_t)which); + if (after_inserted == NULL) + { + add_item_to_array(array, newitem); + return; + } + + newitem->next = after_inserted; + newitem->prev = after_inserted->prev; + after_inserted->prev = newitem; + if (after_inserted == array->child) + { + array->child = newitem; + } + else + { + newitem->prev->next = newitem; + } +} + +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) +{ + if ((parent == NULL) || (replacement == NULL) || (item == NULL)) + { + return false; + } + + if (replacement == item) + { + return true; + } + + replacement->next = item->next; + replacement->prev = item->prev; + + if (replacement->next != NULL) + { + replacement->next->prev = replacement; + } + if (replacement->prev != NULL) + { + replacement->prev->next = replacement; + } + if (parent->child == item) + { + parent->child = replacement; + } + + item->next = NULL; + item->prev = NULL; + cJSON_Delete(item); + + return true; +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) +{ + if (which < 0) + { + return; + } + + cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); +} + +static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) +{ + if ((replacement == NULL) || (string == NULL)) + { + return false; + } + + /* replace the name in the replacement */ + if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) + { + cJSON_free(replacement->string); + } + replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + replacement->type &= ~cJSON_StringIsConst; + + cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); + + return true; +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) +{ + replace_item_in_object(object, string, newitem, false); +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) +{ + replace_item_in_object(object, string, newitem, true); +} + +/* Create basic types: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_NULL; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_True; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = boolean ? cJSON_True : cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Number; + item->valuedouble = num; + + /* use saturation in case of overflow */ + if (num >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (num <= (double)INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)num; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_String; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) + { + item->type = cJSON_String | cJSON_IsReference; + item->valuestring = (char*)cast_away_const(string); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Object | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Array | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Raw; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type=cJSON_Array; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Object; + } + + return item; +} + +/* Create Arrays: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber((double)numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0;a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (strings == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateString(strings[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p,n); + } + p = n; + } + + return a; +} + +/* Duplication */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) +{ + cJSON *newitem = NULL; + cJSON *child = NULL; + cJSON *next = NULL; + cJSON *newchild = NULL; + + /* Bail on bad ptr */ + if (!item) + { + goto fail; + } + /* Create new item */ + newitem = cJSON_New_Item(&global_hooks); + if (!newitem) + { + goto fail; + } + /* Copy over all vars */ + newitem->type = item->type & (~cJSON_IsReference); + newitem->valueint = item->valueint; + newitem->valuedouble = item->valuedouble; + if (item->valuestring) + { + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + if (!newitem->valuestring) + { + goto fail; + } + } + if (item->string) + { + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + if (!newitem->string) + { + goto fail; + } + } + /* If non-recursive, then we're done! */ + if (!recurse) + { + return newitem; + } + /* Walk the ->next chain for the child. */ + child = item->child; + while (child != NULL) + { + newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) + { + goto fail; + } + if (next != NULL) + { + /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + next->next = newchild; + newchild->prev = next; + next = newchild; + } + else + { + /* Set newitem->child and move to it */ + newitem->child = newchild; + next = newchild; + } + child = child->next; + } + + return newitem; + +fail: + if (newitem != NULL) + { + cJSON_Delete(newitem); + } + + return NULL; +} + +static void skip_oneline_comment(char **input) +{ + *input += static_strlen("//"); + + for (; (*input)[0] != '\0'; ++(*input)) + { + if ((*input)[0] == '\n') { + *input += static_strlen("\n"); + return; + } + } +} + +static void skip_multiline_comment(char **input) +{ + *input += static_strlen("/*"); + + for (; (*input)[0] != '\0'; ++(*input)) + { + if (((*input)[0] == '*') && ((*input)[1] == '/')) + { + *input += static_strlen("*/"); + return; + } + } +} + +static void minify_string(char **input, char **output) { + (*output)[0] = (*input)[0]; + *input += static_strlen("\""); + *output += static_strlen("\""); + + + for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { + (*output)[0] = (*input)[0]; + + if ((*input)[0] == '\"') { + (*output)[0] = '\"'; + *input += static_strlen("\""); + *output += static_strlen("\""); + return; + } else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { + (*output)[1] = (*input)[1]; + *input += static_strlen("\""); + *output += static_strlen("\""); + } + } +} + +CJSON_PUBLIC(void) cJSON_Minify(char *json) +{ + char *into = json; + + if (json == NULL) + { + return; + } + + while (json[0] != '\0') + { + switch (json[0]) + { + case ' ': + case '\t': + case '\r': + case '\n': + json++; + break; + + case '/': + if (json[1] == '/') + { + skip_oneline_comment(&json); + } + else if (json[1] == '*') + { + skip_multiline_comment(&json); + } else { + json++; + } + break; + + case '\"': + minify_string(&json, (char**)&into); + break; + + default: + into[0] = json[0]; + json++; + into++; + } + } + + /* and null-terminate. */ + *into = '\0'; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Invalid; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_False; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xff) == cJSON_True; +} + + +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & (cJSON_True | cJSON_False)) != 0; +} +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_NULL; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Number; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_String; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Array; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Object; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Raw; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) +{ + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) + { + return false; + } + + /* check if type is valid */ + switch (a->type & 0xFF) + { + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + case cJSON_Number: + case cJSON_String: + case cJSON_Raw: + case cJSON_Array: + case cJSON_Object: + break; + + default: + return false; + } + + /* identical objects are equal */ + if (a == b) + { + return true; + } + + switch (a->type & 0xFF) + { + /* in these cases and equal type is enough */ + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + return true; + + case cJSON_Number: + if (compare_double(a->valuedouble, b->valuedouble)) + { + return true; + } + return false; + + case cJSON_String: + case cJSON_Raw: + if ((a->valuestring == NULL) || (b->valuestring == NULL)) + { + return false; + } + if (strcmp(a->valuestring, b->valuestring) == 0) + { + return true; + } + + return false; + + case cJSON_Array: + { + cJSON *a_element = a->child; + cJSON *b_element = b->child; + + for (; (a_element != NULL) && (b_element != NULL);) + { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + + a_element = a_element->next; + b_element = b_element->next; + } + + /* one of the arrays is longer than the other */ + if (a_element != b_element) { + return false; + } + + return true; + } + + case cJSON_Object: + { + cJSON *a_element = NULL; + cJSON *b_element = NULL; + cJSON_ArrayForEach(a_element, a) + { + /* TODO This has O(n^2) runtime, which is horrible! */ + b_element = get_object_item(b, a_element->string, case_sensitive); + if (b_element == NULL) + { + return false; + } + + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + } + + /* doing this twice, once on a and b to prevent true comparison if a subset of b + * TODO: Do this the proper way, this is just a fix for now */ + cJSON_ArrayForEach(b_element, b) + { + a_element = get_object_item(a, b_element->string, case_sensitive); + if (a_element == NULL) + { + return false; + } + + if (!cJSON_Compare(b_element, a_element, case_sensitive)) + { + return false; + } + } + + return true; + } + + default: + return false; + } +} + +CJSON_PUBLIC(void *) cJSON_malloc(size_t size) +{ + return global_hooks.allocate(size); +} + +CJSON_PUBLIC(void) cJSON_free(void *object) +{ + global_hooks.deallocate(object); +} diff --git a/src/debug/thirdparty/c/cJSON.h b/src/debug/thirdparty/c/cJSON.h new file mode 100644 index 0000000..21099b4 --- /dev/null +++ b/src/debug/thirdparty/c/cJSON.h @@ -0,0 +1,293 @@ +/* + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef cJSON__h +#define cJSON__h + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) +#define __WINDOWS__ +#endif + +#ifdef __WINDOWS__ + +/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options: + +CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols +CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) +CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol + +For *nix builds that support visibility attribute, you can define similar behavior by + +setting default visibility to hidden by adding +-fvisibility=hidden (for gcc) +or +-xldscope=hidden (for sun cc) +to CFLAGS + +then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does + +*/ + +#define CJSON_CDECL __cdecl +#define CJSON_STDCALL __stdcall + +/* export symbols by default, this is necessary for copy pasting the C and header file */ +#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_EXPORT_SYMBOLS +#endif + +#if defined(CJSON_HIDE_SYMBOLS) +#define CJSON_PUBLIC(type) type CJSON_STDCALL +#elif defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL +#elif defined(CJSON_IMPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL +#endif +#else /* !__WINDOWS__ */ +#define CJSON_CDECL +#define CJSON_STDCALL + +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#else +#define CJSON_PUBLIC(type) type +#endif +#endif + +/* project version */ +#define CJSON_VERSION_MAJOR 1 +#define CJSON_VERSION_MINOR 7 +#define CJSON_VERSION_PATCH 12 + +#include + +/* cJSON Types: */ +#define cJSON_Invalid (0) +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) +#define cJSON_Number (1 << 3) +#define cJSON_String (1 << 4) +#define cJSON_Array (1 << 5) +#define cJSON_Object (1 << 6) +#define cJSON_Raw (1 << 7) /* raw json */ + +#define cJSON_IsReference 256 +#define cJSON_StringIsConst 512 + +/* The cJSON structure: */ +typedef struct cJSON +{ + /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *next; + struct cJSON *prev; + /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + struct cJSON *child; + + /* The type of the item, as above. */ + int type; + + /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + char *valuestring; + /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ + int valueint; + /* The item's number, if type==cJSON_Number */ + double valuedouble; + + /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + char *string; +} cJSON; + +typedef struct cJSON_Hooks +{ + /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ + void *(CJSON_CDECL *malloc_fn)(size_t sz); + void (CJSON_CDECL *free_fn)(void *ptr); +} cJSON_Hooks; + +typedef int cJSON_bool; + +/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. + * This is to prevent stack overflows. */ +#ifndef CJSON_NESTING_LIMIT +#define CJSON_NESTING_LIMIT 1000 +#endif + +/* Precision of double variables comparison */ +#ifndef CJSON_DOUBLE_PRECISION +#define CJSON_DOUBLE_PRECISION .0000000000000001 +#endif + +/* returns the version of cJSON as a string */ +CJSON_PUBLIC(const char*) cJSON_Version(void); + +/* Supply malloc, realloc and free functions to cJSON */ +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); + +/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ +/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); +/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ +/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); + +/* Render a cJSON entity to text for transfer/storage. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); +/* Render a cJSON entity to text for transfer/storage without any formatting. */ +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); +/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); +/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ +/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); +/* Delete a cJSON entity and all subentities. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); + +/* Returns the number of items in an array (or object). */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); +/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); +/* Get item "string" from object. Case insensitive. */ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); +/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); + +/* Check if the item is a string and return its valuestring */ +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item); + +/* These functions check the type of an item */ +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); + +/* These calls create a cJSON item of the appropriate type. */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); +/* raw json */ +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); + +/* Create a string where valuestring references a string so + * it will not be freed by cJSON_Delete */ +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); +/* Create an object/array that only references it's elements so + * they will not be freed by cJSON_Delete */ +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); + +/* These utilities create an Array of count items. + * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count); + +/* Append item to the specified array/object. */ +CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); +/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. + * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before + * writing to `item->string` */ +CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); +/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ +CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); + +/* Remove/Detach items from Arrays/Objects. */ +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); + +/* Update array items. */ +CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); +CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); +CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); +CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); + +/* Duplicate a cJSON item */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); +/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will + * need to be released. With recurse!=0, it will duplicate any children connected to the item. + * The item->next and ->prev pointers are always zero on return from Duplicate. */ +/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. + * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); + +/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. + * The input pointer json cannot point to a read-only address area, such as a string constant, + * but should point to a readable and writable adress area. */ +CJSON_PUBLIC(void) cJSON_Minify(char *json); + +/* Helper functions for creating and adding items to an object at the same time. + * They return the added item or NULL on failure. */ +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); + +/* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) +/* helper for the cJSON_SetNumberValue macro */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) + +/* Macro for iterating over an array or object */ +#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) + +/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ +CJSON_PUBLIC(void *) cJSON_malloc(size_t size); +CJSON_PUBLIC(void) cJSON_free(void *object); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/extension.ts b/src/extension.ts index 4ab9dd7..938c042 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -29,6 +29,7 @@ import { bricksDataService } from "./service/BricksDataService"; import { bricksViewController } from "./controller/BricksViewController"; import { statusBarTimeService } from "./service/StatusBarTimeService"; import { remarkController } from "./controller/RemarkController"; +import { debugContorller } from "./controller/DebugController"; // 激活插件 /** @@ -137,7 +138,8 @@ export async function activate(context: ExtensionContext): Promise { }), commands.registerCommand("lcpr.includeTemplates", (document: TextDocument) => { remarkController.includeTemplates(document); - }) + }), + commands.registerCommand("lcpr.simpleDebug", (uri, testCase?) => debugContorller.debugSolution(uri, testCase)) ); // 设置站点 diff --git a/src/service/DebugService.ts b/src/service/DebugService.ts new file mode 100644 index 0000000..fb282b1 --- /dev/null +++ b/src/service/DebugService.ts @@ -0,0 +1,155 @@ +import * as net from "net"; +// import * as path from "path"; +import * as vscode from "vscode"; +import { IDebugResult } from "../utils/problemUtils"; +import { cppExecutor } from "../debug/executor/cppExecutor"; +import { logOutput } from "../utils/OutputUtils"; +import * as fse from "fs-extra"; +import { fileMeta, getEntryFile, IDebugConfig, IProblemType } from "../utils/problemUtils"; +import problemTypes from "../utils/problemTypes"; + +const debugConfigMap: Map = new Map([ + [ + "javascript", + { + type: "node", + }, + ], + [ + "python3", + { + type: "python", + env: { + PYTHONPATH: "", + }, + }, + ], +]); + +class DebugExecutor { + private server: net.Server; + + constructor() { + this.start(); + } + + private getProblemFunName(language: string, problemType: IProblemType): string { + if (problemType.specialFunName && problemType.specialFunName[language]) { + return problemType.specialFunName[language]; + } + return problemType.funName; + } + + public async execute(filePath: string, testString: string, language: string): Promise { + if (this.server == null || this.server.address() == null) { + vscode.window.showErrorMessage("Debug server error, maybe you can restart vscode."); + return; + } + + if (language === "cpp") { + return await cppExecutor.execute(filePath, testString, language, (this.server.address() as net.AddressInfo).port); + } + + const debugConfig: undefined | IDebugConfig = debugConfigMap.get(language); + if (debugConfig == null) { + vscode.window.showErrorMessage("Notsupported language."); + return; + } + + const fileContent: Buffer = await fse.readFile(filePath); + const meta: { id: string; lang: string } | null = fileMeta(fileContent.toString()); + if (meta == null) { + vscode.window.showErrorMessage( + "File meta info has been changed, please check the content: '@lc app=leetcode.cn id=xx lang=xx'." + ); + return; + } + const problemType: IProblemType = problemTypes[meta.id]; + if (problemType == null) { + vscode.window.showErrorMessage(`Notsupported problem: ${meta.id}.`); + return; + } + + debugConfig.program = await getEntryFile(meta.lang, meta.id); + + const funName: string = this.getProblemFunName(language, problemType); + + if (language === "javascript") { + // check whether module.exports is exist or not + const moduleExportsReg: RegExp = new RegExp(`module.exports = ${problemType.funName};`); + if (!moduleExportsReg.test(fileContent.toString())) { + fse.writeFile( + filePath, + fileContent.toString() + + `\n// @after-stub-for-debug-begin\nmodule.exports = ${funName};\n// @after-stub-for-debug-end` + ); + } + } else if (language === "python3") { + // check whether module.exports is exist or not + const moduleExportsReg: RegExp = /# @before-stub-for-debug-begin/; + if (!moduleExportsReg.test(fileContent.toString())) { + await fse.writeFile( + filePath, + `# @before-stub-for-debug-begin\nfrom python3problem${meta.id} import *\nfrom typing import *\n# @before-stub-for-debug-end\n\n` + + fileContent.toString() + ); + } + debugConfig.env!.PYTHONPATH = debugConfig.program; + } + + const args: string[] = [ + filePath, + testString, + problemType.funName, + problemType.paramTypes.join(","), + problemType.returnType, + meta.id, + (this.server.address() as net.AddressInfo).port.toString(), + ]; + vscode.debug.startDebugging( + undefined, + Object.assign({}, debugConfig, { + request: "launch", + name: "Launch Program", + args, + }) + ); + + return; + } + + private async start(): Promise { + this.server = net.createServer((clientSock: net.Socket) => { + clientSock.setEncoding("utf8"); + + clientSock.on("data", async (data: Buffer) => { + const result: IDebugResult = JSON.parse(data.toString()); + if (result.type === "error") { + vscode.window.showErrorMessage(result.message); + } else { + // const leetcodeResult: string = await leetCodeExecutor.testSolution( + // result.filePath, + // parseTestString(result.testString.replace(/\\"/g, '"')), + // ); + // if (!leetcodeResult) { + // return; + // } + // leetCodeSubmissionProvider.show(leetcodeResult); + } + }); + + clientSock.on("error", (error: Error) => { + logOutput.appendLine(error.toString()); + }); + }); + + this.server.on("error", (error: Error) => { + logOutput.appendLine(error.toString()); + }); + + // listen on a random port + this.server.listen({ port: 0, host: "127.0.0.1" }); + } +} + +export const debugExecutor: DebugExecutor = new DebugExecutor(); diff --git a/src/service/FileButtonService.ts b/src/service/FileButtonService.ts index 57a3c9e..0245671 100644 --- a/src/service/FileButtonService.ts +++ b/src/service/FileButtonService.ts @@ -107,14 +107,28 @@ export class FileButtonService implements vscode.CodeLensProvider { /** * createCase */ - public createCase(codeLensLine, document, testCase) { + public createCase(codeLensLine, document, testCase): vscode.CodeLens[] { const range: vscode.Range = new vscode.Range(codeLensLine, 0, codeLensLine, 0); - return new vscode.CodeLens(range, { - title: "case", - command: "lcpr.tesCaseArea", - arguments: [document.uri, testCase], - }); + const temp_result: vscode.CodeLens[] = []; + + temp_result.push( + new vscode.CodeLens(range, { + title: "case", + command: "lcpr.tesCaseArea", + arguments: [document.uri, testCase], + }) + ); + + // temp_result.push( + // new vscode.CodeLens(range, { + // title: "debug", + // command: "lcpr.simpleDebug", + // arguments: [document.uri, testCase], + // }) + // ); + + return temp_result; } public singleLineFlag = { @@ -215,7 +229,7 @@ export class FileButtonService implements vscode.CodeLensProvider { } if (caseFlag && lineContent.indexOf("@lcpr case=end") >= 0) { - codeLens.push(this.createCase(i, document, curCase)); + this.createCase(i, document, curCase).forEach((x) => codeLens.push(x)); curCase = ""; caseFlag = false; } diff --git a/src/utils/SystemUtils.ts b/src/utils/SystemUtils.ts index 2d03718..78dedb6 100644 --- a/src/utils/SystemUtils.ts +++ b/src/utils/SystemUtils.ts @@ -13,6 +13,7 @@ import * as path from "path"; import { IProblem, langExt } from "../model/Model"; import { executeCommand } from "./CliUtils"; import { isUseVscodeNode, isUseWsl } from "./ConfigUtils"; +import { Uri, window, TextEditor } from "vscode"; export function isWindows(): boolean { return process.platform === "win32"; @@ -123,3 +124,49 @@ export function getyyyymmdd(timeSecond: number | undefined): string { const newDate = `${year}${month}${day}`; return newDate; } + +/** + * "If the ComSpec environment variable is not set, or if it is set to cmd.exe, then return true." + * + * The ComSpec environment variable is set to the path of the command processor. On Windows, this is + * usually cmd.exe. On Linux, it is usually bash + * @returns A boolean value. + */ +export function usingCmd(): boolean { + const comSpec: string | undefined = process.env.ComSpec; + // 'cmd.exe' is used as a fallback if process.env.ComSpec is unavailable. + if (!comSpec) { + return true; + } + + if (comSpec.indexOf("cmd.exe") > -1) { + return true; + } + return false; +} + +// 获取当前文件的路径 +/** + * It returns the path of the currently active file, or undefined if there is no active file + * @param [uri] - The file path to open. + * @returns A promise that resolves to a string or undefined. + */ +export async function getTextEditorFilePathByUri(uri?: Uri): Promise { + let textEditor: TextEditor | undefined; + if (uri) { + textEditor = await window.showTextDocument(uri, { + preview: false, + }); + } else { + textEditor = window.activeTextEditor; + } + + if (!textEditor) { + return undefined; + } + if (textEditor.document.isDirty && !(await textEditor.document.save())) { + window.showWarningMessage("请先保存当前文件"); + return undefined; + } + return useWsl() ? toWslPath(textEditor.document.uri.fsPath) : textEditor.document.uri.fsPath; +} diff --git a/src/utils/problemTypes.ts b/src/utils/problemTypes.ts new file mode 100644 index 0000000..311bc2b --- /dev/null +++ b/src/utils/problemTypes.ts @@ -0,0 +1,5318 @@ +export default { + 1: { + funName: "twoSum", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[2,7,11,15]\\n9", + }, + 2: { + funName: "addTwoNumbers", + paramTypes: ["ListNode", "ListNode"], + returnType: "ListNode", + testCase: "[2,4,3]\\n[5,6,4]", + }, + 3: { + funName: "lengthOfLongestSubstring", + paramTypes: ["string"], + returnType: "number", + testCase: '"abcabcbb"', + }, + 4: { + funName: "findMedianSortedArrays", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[1,3]\\n[2]", + }, + 5: { + funName: "longestPalindrome", + paramTypes: ["string"], + returnType: "string", + testCase: '"babad"', + }, + 6: { + funName: "convert", + paramTypes: ["string", "number"], + returnType: "string", + testCase: '"PAYPALISHIRING"\\n3', + }, + 7: { + funName: "reverse", + paramTypes: ["number"], + returnType: "number", + testCase: "123", + }, + 8: { + funName: "myAtoi", + paramTypes: ["string"], + returnType: "number", + testCase: '"42"', + }, + 9: { + funName: "isPalindrome", + paramTypes: ["number"], + returnType: "boolean", + testCase: "121", + }, + 10: { + funName: "isMatch", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"aa"\\n"a"', + }, + 11: { + funName: "maxArea", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,8,6,2,5,4,8,3,7]", + }, + 12: { + funName: "intToRoman", + paramTypes: ["number"], + returnType: "string", + testCase: "3", + }, + 13: { + funName: "romanToInt", + paramTypes: ["string"], + returnType: "number", + testCase: '"III"', + }, + 14: { + funName: "longestCommonPrefix", + paramTypes: ["string[]"], + returnType: "string", + testCase: '["flower","flow","flight"]', + }, + 15: { + funName: "threeSum", + paramTypes: ["number[]"], + returnType: "number[][]", + testCase: "[-1,0,1,2,-1,-4]", + }, + 16: { + funName: "threeSumClosest", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[-1,2,1,-4]\\n1", + }, + 17: { + funName: "letterCombinations", + paramTypes: ["string"], + returnType: "string[]", + testCase: '"23"', + }, + 18: { + funName: "fourSum", + paramTypes: ["number[]", "number"], + returnType: "number[][]", + testCase: "[1,0,-1,0,-2,2]\\n0", + }, + 19: { + funName: "removeNthFromEnd", + paramTypes: ["ListNode", "number"], + returnType: "ListNode", + testCase: "[1,2,3,4,5]\\n2", + }, + 20: { + funName: "isValid", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"()"', + }, + 21: { + funName: "mergeTwoLists", + paramTypes: ["ListNode", "ListNode"], + returnType: "ListNode", + testCase: "[1,2,4]\\n[1,3,4]", + }, + 22: { + funName: "generateParenthesis", + paramTypes: ["number"], + returnType: "string[]", + testCase: "3", + }, + 23: { + funName: "mergeKLists", + paramTypes: ["ListNode[]"], + returnType: "ListNode", + testCase: "[[1,4,5],[1,3,4],[2,6]]", + }, + 24: { + funName: "swapPairs", + paramTypes: ["ListNode"], + returnType: "ListNode", + testCase: "[1,2,3,4]", + }, + 25: { + funName: "reverseKGroup", + paramTypes: ["ListNode", "number"], + returnType: "ListNode", + testCase: "[1,2,3,4,5]\\n2", + }, + 26: { + funName: "removeDuplicates", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,1,2]", + }, + 27: { + funName: "removeElement", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[3,2,2,3]\\n3", + }, + 28: { + funName: "strStr", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"hello"\\n"ll"', + }, + 29: { + funName: "divide", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "10\\n3", + }, + 30: { + funName: "findSubstring", + paramTypes: ["string", "string[]"], + returnType: "number[]", + testCase: '"barfoothefoobarman"\\n["foo","bar"]', + }, + 31: { + funName: "nextPermutation", + paramTypes: ["number[]"], + returnType: "void", + testCase: "[1,2,3]", + }, + 32: { + funName: "longestValidParentheses", + paramTypes: ["string"], + returnType: "number", + testCase: '"(()"', + }, + 33: { + funName: "search", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[4,5,6,7,0,1,2]\\n0", + }, + 34: { + funName: "searchRange", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[5,7,7,8,8,10]\\n8", + }, + 35: { + funName: "searchInsert", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,3,5,6]\\n5", + }, + 36: { + funName: "isValidSudoku", + paramTypes: ["character[][]"], + returnType: "boolean", + testCase: + '[["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]', + }, + 37: { + funName: "solveSudoku", + paramTypes: ["character[][]"], + returnType: "void", + testCase: + '[["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]', + }, + 38: { + funName: "countAndSay", + paramTypes: ["number"], + returnType: "string", + testCase: "1", + }, + 39: { + funName: "combinationSum", + paramTypes: ["number[]", "number"], + returnType: "number[][]", + testCase: "[2,3,6,7]\\n7", + }, + 40: { + funName: "combinationSum2", + paramTypes: ["number[]", "number"], + returnType: "number[][]", + testCase: "[10,1,2,7,6,1,5]\\n8", + }, + 41: { + funName: "firstMissingPositive", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,0]", + }, + 42: { + funName: "trap", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[0,1,0,2,1,0,1,3,2,1,2,1]", + }, + 43: { + funName: "multiply", + paramTypes: ["string", "string"], + returnType: "string", + testCase: '"2"\\n"3"', + }, + 44: { + funName: "isMatch", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"aa"\\n"a"', + }, + 45: { + funName: "jump", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,3,1,1,4]", + }, + 46: { + funName: "permute", + paramTypes: ["number[]"], + returnType: "number[][]", + testCase: "[1,2,3]", + }, + 47: { + funName: "permuteUnique", + paramTypes: ["number[]"], + returnType: "number[][]", + testCase: "[1,1,2]", + }, + 48: { + funName: "rotate", + paramTypes: ["number[][]"], + returnType: "void", + testCase: "[[1,2,3],[4,5,6],[7,8,9]]", + }, + 49: { + funName: "groupAnagrams", + paramTypes: ["string[]"], + returnType: "string[][]", + testCase: '["eat","tea","tan","ate","nat","bat"]', + }, + 50: { + funName: "myPow", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "2.00000\\n10", + }, + 51: { + funName: "solveNQueens", + paramTypes: ["number"], + returnType: "string[][]", + testCase: "4", + }, + 52: { + funName: "totalNQueens", + paramTypes: ["number"], + returnType: "number", + testCase: "4", + }, + 53: { + funName: "maxSubArray", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[-2,1,-3,4,-1,2,1,-5,4]", + }, + 54: { + funName: "spiralOrder", + paramTypes: ["number[][]"], + returnType: "number[]", + testCase: "[[1,2,3],[4,5,6],[7,8,9]]", + }, + 55: { + funName: "canJump", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[2,3,1,1,4]", + }, + 56: { + funName: "merge", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[1,3],[2,6],[8,10],[15,18]]", + }, + 57: { + funName: "insert", + paramTypes: ["number[][]", "number[]"], + returnType: "number[][]", + testCase: "[[1,3],[6,9]]\\n[2,5]", + }, + 58: { + funName: "lengthOfLastWord", + paramTypes: ["string"], + returnType: "number", + testCase: '"Hello World"', + }, + 59: { + funName: "generateMatrix", + paramTypes: ["number"], + returnType: "number[][]", + testCase: "3", + }, + 60: { + funName: "getPermutation", + paramTypes: ["number", "number"], + returnType: "string", + testCase: "3\\n3", + }, + 61: { + funName: "rotateRight", + paramTypes: ["ListNode", "number"], + returnType: "ListNode", + testCase: "[1,2,3,4,5]\\n2", + }, + 62: { + funName: "uniquePaths", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "3\\n2", + }, + 63: { + funName: "uniquePathsWithObstacles", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,0,0],[0,1,0],[0,0,0]]", + }, + 64: { + funName: "minPathSum", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,3,1],[1,5,1],[4,2,1]]", + }, + 65: { + funName: "isNumber", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"0"', + }, + 66: { + funName: "plusOne", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[1,2,3]", + }, + 67: { + funName: "addBinary", + paramTypes: ["string", "string"], + returnType: "string", + testCase: '"11"\\n"1"', + }, + 68: { + funName: "fullJustify", + paramTypes: ["string[]", "number"], + returnType: "string[]", + testCase: '["This", "is", "an", "example", "of", "text", "justification."]\\n16', + }, + 69: { + funName: "mySqrt", + paramTypes: ["number"], + returnType: "number", + testCase: "4", + }, + 70: { + funName: "climbStairs", + paramTypes: ["number"], + returnType: "number", + testCase: "2", + }, + 71: { + funName: "simplifyPath", + paramTypes: ["string"], + returnType: "string", + testCase: '"/home/"', + }, + 72: { + funName: "minDistance", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"horse"\\n"ros"', + }, + 73: { + funName: "setZeroes", + paramTypes: ["number[][]"], + returnType: "void", + testCase: "[[1,1,1],[1,0,1],[1,1,1]]", + }, + 74: { + funName: "searchMatrix", + paramTypes: ["number[][]", "number"], + returnType: "boolean", + testCase: "[[1,3,5,7],[10,11,16,20],[23,30,34,50]]\\n3", + }, + 75: { + funName: "sortColors", + paramTypes: ["number[]"], + returnType: "void", + testCase: "[2,0,2,1,1,0]", + }, + 76: { + funName: "minWindow", + paramTypes: ["string", "string"], + returnType: "string", + testCase: '"ADOBECODEBANC"\\n"ABC"', + }, + 77: { + funName: "combine", + paramTypes: ["number", "number"], + returnType: "number[][]", + testCase: "4\\n2", + }, + 78: { + funName: "subsets", + paramTypes: ["number[]"], + returnType: "number[][]", + testCase: "[1,2,3]", + }, + 79: { + funName: "exist", + paramTypes: ["character[][]", "string"], + returnType: "boolean", + testCase: '[["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]\\n"ABCCED"', + }, + 80: { + funName: "removeDuplicates", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,1,1,2,2,3]", + }, + 81: { + funName: "search", + paramTypes: ["number[]", "number"], + returnType: "boolean", + testCase: "[2,5,6,0,0,1,2]\\n0", + }, + 82: { + funName: "deleteDuplicates", + paramTypes: ["ListNode"], + returnType: "ListNode", + testCase: "[1,2,3,3,4,4,5]", + }, + 83: { + funName: "deleteDuplicates", + paramTypes: ["ListNode"], + returnType: "ListNode", + testCase: "[1,1,2]", + }, + 84: { + funName: "largestRectangleArea", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,1,5,6,2,3]", + }, + 85: { + funName: "maximalRectangle", + paramTypes: ["character[][]"], + returnType: "number", + testCase: '[["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]', + }, + 86: { + funName: "partition", + paramTypes: ["ListNode", "number"], + returnType: "ListNode", + testCase: "[1,4,3,2,5,2]\\n3", + }, + 87: { + funName: "isScramble", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"great"\\n"rgeat"', + }, + 88: { + funName: "merge", + paramTypes: ["number[]", "number", "number[]", "number"], + returnType: "void", + testCase: "[1,2,3,0,0,0]\\n3\\n[2,5,6]\\n3", + }, + 89: { + funName: "grayCode", + paramTypes: ["number"], + returnType: "number[]", + testCase: "2", + }, + 90: { + funName: "subsetsWithDup", + paramTypes: ["number[]"], + returnType: "number[][]", + testCase: "[1,2,2]", + }, + 91: { + funName: "numDecodings", + paramTypes: ["string"], + returnType: "number", + testCase: '"12"', + }, + 92: { + funName: "reverseBetween", + paramTypes: ["ListNode", "number", "number"], + returnType: "ListNode", + testCase: "[1,2,3,4,5]\\n2\\n4", + }, + 93: { + funName: "restoreIpAddresses", + paramTypes: ["string"], + returnType: "string[]", + testCase: '"25525511135"', + }, + 94: { + funName: "inorderTraversal", + paramTypes: ["TreeNode"], + returnType: "number[]", + testCase: "[1,null,2,3]", + }, + 95: { + funName: "generateTrees", + paramTypes: ["number"], + returnType: "TreeNode[]", + testCase: "3", + }, + 96: { + funName: "numTrees", + paramTypes: ["number"], + returnType: "number", + testCase: "3", + }, + 97: { + funName: "isInterleave", + paramTypes: ["string", "string", "string"], + returnType: "boolean", + testCase: '"aabcc"\\n"dbbca"\\n"aadbbcbcac"', + }, + 98: { + funName: "isValidBST", + paramTypes: ["TreeNode"], + returnType: "boolean", + testCase: "[2,1,3]", + }, + 99: { + funName: "recoverTree", + paramTypes: ["TreeNode"], + returnType: "void", + testCase: "[1,3,null,null,2]", + }, + 100: { + funName: "isSameTree", + paramTypes: ["TreeNode", "TreeNode"], + returnType: "boolean", + testCase: "[1,2,3]\\n[1,2,3]", + }, + 101: { + funName: "isSymmetric", + paramTypes: ["TreeNode"], + returnType: "boolean", + testCase: "[1,2,2,3,4,4,3]", + }, + 102: { + funName: "levelOrder", + paramTypes: ["TreeNode"], + returnType: "number[][]", + testCase: "[3,9,20,null,null,15,7]", + }, + 103: { + funName: "zigzagLevelOrder", + paramTypes: ["TreeNode"], + returnType: "number[][]", + testCase: "[3,9,20,null,null,15,7]", + }, + 104: { + funName: "maxDepth", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[3,9,20,null,null,15,7]", + }, + 105: { + funName: "buildTree", + paramTypes: ["number[]", "number[]"], + returnType: "TreeNode", + testCase: "[3,9,20,15,7]\\n[9,3,15,20,7]", + }, + 106: { + funName: "buildTree", + paramTypes: ["number[]", "number[]"], + returnType: "TreeNode", + testCase: "[9,3,15,20,7]\\n[9,15,7,20,3]", + }, + 107: { + funName: "levelOrderBottom", + paramTypes: ["TreeNode"], + returnType: "number[][]", + testCase: "[3,9,20,null,null,15,7]", + }, + 108: { + funName: "sortedArrayToBST", + paramTypes: ["number[]"], + returnType: "TreeNode", + testCase: "[-10,-3,0,5,9]", + }, + 109: { + funName: "sortedListToBST", + paramTypes: ["ListNode"], + returnType: "TreeNode", + testCase: "[-10,-3,0,5,9]", + }, + 110: { + funName: "isBalanced", + paramTypes: ["TreeNode"], + returnType: "boolean", + testCase: "[3,9,20,null,null,15,7]", + }, + 111: { + funName: "minDepth", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[3,9,20,null,null,15,7]", + }, + 112: { + funName: "hasPathSum", + paramTypes: ["TreeNode", "number"], + returnType: "boolean", + testCase: "[5,4,8,11,null,13,4,7,2,null,null,null,1]\\n22", + }, + 113: { + funName: "pathSum", + paramTypes: ["TreeNode", "number"], + returnType: "number[][]", + testCase: "[5,4,8,11,null,13,4,7,2,null,null,5,1]\\n22", + }, + 114: { + funName: "flatten", + paramTypes: ["TreeNode"], + returnType: "void", + testCase: "[1,2,5,3,4,null,6]", + }, + 115: { + funName: "numDistinct", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"rabbbit"\\n"rabbit"', + }, + 116: { + funName: "connect", + paramTypes: ["Node"], + returnType: "Node", + testCase: "[1,2,3,4,5,6,7]", + }, + 117: { + funName: "connect", + paramTypes: ["Node"], + returnType: "Node", + testCase: "[1,2,3,4,5,null,7]", + }, + 118: { + funName: "generate", + paramTypes: ["number"], + returnType: "number[][]", + testCase: "5", + }, + 119: { + funName: "getRow", + paramTypes: ["number"], + returnType: "number[]", + testCase: "3", + }, + 120: { + funName: "minimumTotal", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[2],[3,4],[6,5,7],[4,1,8,3]]", + }, + 121: { + funName: "maxProfit", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[7,1,5,3,6,4]", + }, + 122: { + funName: "maxProfit", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[7,1,5,3,6,4]", + }, + 123: { + funName: "maxProfit", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,3,5,0,0,3,1,4]", + }, + 124: { + funName: "maxPathSum", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[1,2,3]", + }, + 125: { + funName: "isPalindrome", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"A man, a plan, a canal: Panama"', + }, + 126: { + funName: "findLadders", + paramTypes: ["string", "string", "string[]"], + returnType: "string[][]", + testCase: '"hit"\\n"cog"\\n["hot","dot","dog","lot","log","cog"]', + }, + 127: { + funName: "ladderLength", + paramTypes: ["string", "string", "string[]"], + returnType: "number", + testCase: '"hit"\\n"cog"\\n["hot","dot","dog","lot","log","cog"]', + }, + 128: { + funName: "longestConsecutive", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[100,4,200,1,3,2]", + }, + 129: { + funName: "sumNumbers", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[1,2,3]", + }, + 130: { + funName: "solve", + paramTypes: ["character[][]"], + returnType: "void", + testCase: '[["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]', + }, + 131: { + funName: "partition", + paramTypes: ["string"], + returnType: "string[][]", + testCase: '"aab"', + }, + 132: { + funName: "minCut", + paramTypes: ["string"], + returnType: "number", + testCase: '"aab"', + }, + 133: { + funName: "cloneGraph", + paramTypes: ["Node"], + returnType: "Node", + testCase: "[[2,4],[1,3],[2,4],[1,3]]", + }, + 134: { + funName: "canCompleteCircuit", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[1,2,3,4,5]\\n[3,4,5,1,2]", + }, + 135: { + funName: "candy", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,0,2]", + }, + 136: { + funName: "singleNumber", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,2,1]", + }, + 137: { + funName: "singleNumber", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,2,3,2]", + }, + 138: { + funName: "copyRandomList", + paramTypes: ["Node"], + returnType: "Node", + testCase: "[[7,null],[13,0],[11,4],[10,2],[1,0]]", + }, + 139: { + funName: "wordBreak", + paramTypes: ["string", "string[]"], + returnType: "boolean", + testCase: '"leetcode"\\n["leet","code"]', + }, + 140: { + funName: "wordBreak", + paramTypes: ["string", "string[]"], + returnType: "string[]", + testCase: '"catsanddog"\\n["cat","cats","and","sand","dog"]', + }, + 141: { + funName: "hasCycle", + paramTypes: ["ListNode"], + returnType: "boolean", + testCase: "[3,2,0,-4]\\n1", + }, + 142: { + funName: "detectCycle", + paramTypes: ["ListNode"], + returnType: "ListNode", + testCase: "[3,2,0,-4]\\n1", + }, + 143: { + funName: "reorderList", + paramTypes: ["ListNode"], + returnType: "void", + testCase: "[1,2,3,4]", + }, + 144: { + funName: "preorderTraversal", + paramTypes: ["TreeNode"], + returnType: "number[]", + testCase: "[1,null,2,3]", + }, + 145: { + funName: "postorderTraversal", + paramTypes: ["TreeNode"], + returnType: "number[]", + testCase: "[1,null,2,3]", + }, + 146: { + funName: "LRUCache", + paramTypes: ["number"], + returnType: "void", + testCase: + '["LRUCache","put","put","get","put","get","put","get","get","get"]\\n[[2],[1,1],[2,2],[1],[3,3],[2],[4,4],[1],[3],[4]]', + }, + 147: { + funName: "insertionSortList", + paramTypes: ["ListNode"], + returnType: "ListNode", + testCase: "[4,2,1,3]", + }, + 148: { + funName: "sortList", + paramTypes: ["ListNode"], + returnType: "ListNode", + testCase: "[4,2,1,3]", + }, + 149: { + funName: "maxPoints", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,1],[2,2],[3,3]]", + }, + 150: { + funName: "evalRPN", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["2","1","+","3","*"]', + }, + 151: { + funName: "reverseWords", + paramTypes: ["string"], + returnType: "string", + testCase: '"the sky is blue"', + }, + 152: { + funName: "maxProduct", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,3,-2,4]", + }, + 153: { + funName: "findMin", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,4,5,1,2]", + }, + 154: { + funName: "findMin", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,3,5]", + }, + 155: { + funName: "MinStack", + paramTypes: [], + returnType: "void", + testCase: '["MinStack","push","push","push","getMin","pop","top","getMin"]\\n[[],[-2],[0],[-3],[],[],[],[]]', + }, + 160: { + funName: "getIntersectionNode", + paramTypes: ["ListNode", "ListNode"], + returnType: "ListNode", + testCase: "8\\n[4,1,8,4,5]\\n[5,0,1,8,4,5]\\n2\\n3", + }, + 162: { + funName: "findPeakElement", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3,1]", + }, + 164: { + funName: "maximumGap", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,6,9,1]", + }, + 165: { + funName: "compareVersion", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"0.1"\\n"1.1"', + }, + 166: { + funName: "fractionToDecimal", + paramTypes: ["number", "number"], + returnType: "string", + testCase: "1\\n2", + }, + 167: { + funName: "twoSum", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[2,7,11,15]\\n9", + }, + 168: { + funName: "convertToTitle", + paramTypes: ["number"], + returnType: "string", + testCase: "1", + }, + 169: { + funName: "majorityElement", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,2,3]", + }, + 171: { + funName: "titleToNumber", + paramTypes: ["string"], + returnType: "number", + testCase: '"A"', + }, + 172: { + funName: "trailingZeroes", + paramTypes: ["number"], + returnType: "number", + testCase: "3", + }, + 173: { + funName: "BSTIterator", + paramTypes: ["TreeNode"], + returnType: "void", + testCase: + '["BSTIterator","next","next","hasNext","next","hasNext","next","hasNext","next","hasNext"]\\n[[[7,3,15,null,null,9,20]],[null],[null],[null],[null],[null],[null],[null],[null],[null]]', + }, + 174: { + funName: "calculateMinimumHP", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[-2,-3,3],[-5,-10,1],[10,30,-5]]", + }, + 179: { + funName: "largestNumber", + paramTypes: ["number[]"], + returnType: "string", + testCase: "[10,2]", + }, + 187: { + funName: "findRepeatedDnaSequences", + paramTypes: ["string"], + returnType: "string[]", + testCase: '"AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"', + }, + 188: { + funName: "maxProfit", + paramTypes: ["number", "number[]"], + returnType: "number", + testCase: "2\\n[2,4,1]", + }, + 189: { + funName: "rotate", + paramTypes: ["number[]", "number"], + returnType: "void", + testCase: "[1,2,3,4,5,6,7]\\n3", + }, + 190: { + funName: "reverseBits", + paramTypes: ["number"], + returnType: "number", + testCase: "00000010100101000001111010011100", + }, + 191: { + funName: "hammingWeight", + paramTypes: ["number"], + returnType: "number", + testCase: "00000000000000000000000000001011", + }, + 198: { + funName: "rob", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3,1]", + }, + 199: { + funName: "rightSideView", + paramTypes: ["TreeNode"], + returnType: "number[]", + testCase: "[1,2,3,null,5,null,4]", + }, + 200: { + funName: "numIslands", + paramTypes: ["character[][]"], + returnType: "number", + testCase: '[["1","1","1","1","0"],["1","1","0","1","0"],["1","1","0","0","0"],["0","0","0","0","0"]]', + }, + 201: { + funName: "rangeBitwiseAnd", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "5\\n7", + }, + 202: { + funName: "isHappy", + paramTypes: ["number"], + returnType: "boolean", + testCase: "19", + }, + 203: { + funName: "removeElements", + paramTypes: ["ListNode", "number"], + returnType: "ListNode", + testCase: "[1,2,6,3,4,5,6]\\n6", + }, + 204: { + funName: "countPrimes", + paramTypes: ["number"], + returnType: "number", + testCase: "10", + }, + 205: { + funName: "isIsomorphic", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"egg"\\n"add"', + }, + 206: { + funName: "reverseList", + paramTypes: ["ListNode"], + returnType: "ListNode", + testCase: "[1,2,3,4,5]", + }, + 207: { + funName: "canFinish", + paramTypes: ["number", "number[][]"], + returnType: "boolean", + testCase: "2\\n[[1,0]]", + }, + 208: { + funName: "Trie", + paramTypes: [], + returnType: "void", + testCase: + '["Trie","insert","search","search","startsWith","insert","search"]\\n[[],["apple"],["apple"],["app"],["app"],["app"],["app"]]', + }, + 209: { + funName: "minSubArrayLen", + paramTypes: ["number", "number[]"], + returnType: "number", + testCase: "7\\n[2,3,1,2,4,3]", + }, + 210: { + funName: "findOrder", + paramTypes: ["number", "number[][]"], + returnType: "number[]", + testCase: "2\\n[[1,0]]", + }, + 211: { + funName: "WordDictionary", + paramTypes: [], + returnType: "void", + testCase: + '["WordDictionary","addWord","addWord","addWord","search","search","search","search"]\\n[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]', + }, + 212: { + funName: "findWords", + paramTypes: ["character[][]", "string[]"], + returnType: "string[]", + testCase: '[["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]]\\n["oath","pea","eat","rain"]', + }, + 213: { + funName: "rob", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,3,2]", + }, + 214: { + funName: "shortestPalindrome", + paramTypes: ["string"], + returnType: "string", + testCase: '"aacecaaa"', + }, + 215: { + funName: "findKthLargest", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[3,2,1,5,6,4]\\n2", + }, + 216: { + funName: "combinationSum3", + paramTypes: ["number", "number"], + returnType: "number[][]", + testCase: "3\\n7", + }, + 217: { + funName: "containsDuplicate", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,2,3,1]", + }, + 218: { + funName: "getSkyline", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]", + }, + 219: { + funName: "containsNearbyDuplicate", + paramTypes: ["number[]", "number"], + returnType: "boolean", + testCase: "[1,2,3,1]\\n3", + }, + 220: { + funName: "containsNearbyAlmostDuplicate", + paramTypes: ["number[]", "number", "number"], + returnType: "boolean", + testCase: "[1,2,3,1]\\n3\\n0", + }, + 221: { + funName: "maximalSquare", + paramTypes: ["character[][]"], + returnType: "number", + testCase: '[["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]', + }, + 222: { + funName: "countNodes", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[1,2,3,4,5,6]", + }, + 223: { + funName: "computeArea", + paramTypes: ["number", "number", "number", "number", "number", "number", "number", "number"], + returnType: "number", + testCase: "-3\\n0\\n3\\n4\\n0\\n-1\\n9\\n2", + }, + 224: { + funName: "calculate", + paramTypes: ["string"], + returnType: "number", + testCase: '"1 + 1"', + }, + 225: { + funName: "MyStack", + paramTypes: [], + returnType: "void", + testCase: '["MyStack","push","push","top","pop","empty"]\\n[[],[1],[2],[],[],[]]', + }, + 226: { + funName: "invertTree", + paramTypes: ["TreeNode"], + returnType: "TreeNode", + testCase: "[4,2,7,1,3,6,9]", + }, + 227: { + funName: "calculate", + paramTypes: ["string"], + returnType: "number", + testCase: '"3+2*2"', + }, + 228: { + funName: "summaryRanges", + paramTypes: ["number[]"], + returnType: "string[]", + testCase: "[0,1,2,4,5,7]", + }, + 229: { + funName: "majorityElement", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[3,2,3]", + }, + 230: { + funName: "kthSmallest", + paramTypes: ["TreeNode", "number"], + returnType: "number", + testCase: "[3,1,4,null,2]\\n1", + }, + 231: { + funName: "isPowerOfTwo", + paramTypes: ["number"], + returnType: "boolean", + testCase: "1", + }, + 232: { + funName: "MyQueue", + paramTypes: [], + returnType: "void", + testCase: '["MyQueue","push","push","peek","pop","empty"]\\n[[],[1],[2],[],[],[]]', + }, + 233: { + funName: "countDigitOne", + paramTypes: ["number"], + returnType: "number", + testCase: "13", + }, + 234: { + funName: "isPalindrome", + paramTypes: ["ListNode"], + returnType: "boolean", + testCase: "[1,2]", + }, + 235: { + funName: "lowestCommonAncestor", + paramTypes: ["TreeNode", "TreeNode", "TreeNode"], + returnType: "TreeNode", + testCase: "[6,2,8,0,4,7,9,null,null,3,5]\\n2\\n8", + }, + 236: { + funName: "lowestCommonAncestor", + paramTypes: ["TreeNode", "TreeNode", "TreeNode"], + returnType: "TreeNode", + testCase: "[3,5,1,6,2,0,8,null,null,7,4]\\n5\\n1", + }, + 237: { + funName: "deleteNode", + paramTypes: ["ListNode"], + returnType: "void", + testCase: "[4,5,1,9]\\n5", + }, + 238: { + funName: "productExceptSelf", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[1,2,3,4]", + }, + 239: { + funName: "maxSlidingWindow", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[1,3,-1,-3,5,3,6,7]\\n3", + }, + 240: { + funName: "searchMatrix", + paramTypes: ["number[][]", "number"], + returnType: "boolean", + testCase: "[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]]\\n5", + }, + 241: { + funName: "diffWaysToCompute", + paramTypes: ["string"], + returnType: "number[]", + testCase: '"2-1-1"', + }, + 242: { + funName: "isAnagram", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"anagram"\\n"nagaram"', + }, + 257: { + funName: "binaryTreePaths", + paramTypes: ["TreeNode"], + returnType: "string[]", + testCase: "[1,2,3,null,5]", + }, + 258: { + funName: "addDigits", + paramTypes: ["number"], + returnType: "number", + testCase: "38", + }, + 260: { + funName: "singleNumber", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[1,2,1,3,2,5]", + }, + 263: { + funName: "isUgly", + paramTypes: ["number"], + returnType: "boolean", + testCase: "6", + }, + 264: { + funName: "nthUglyNumber", + paramTypes: ["number"], + returnType: "number", + testCase: "10", + }, + 268: { + funName: "missingNumber", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,0,1]", + }, + 273: { + funName: "numberToWords", + paramTypes: ["number"], + returnType: "string", + testCase: "123", + }, + 274: { + funName: "hIndex", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,0,6,1,5]", + }, + 275: { + funName: "hIndex", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[0,1,3,5,6]", + }, + 278: { + funName: "firstBadVersion", + specialFunName: { + javascript: "solution", + }, + // changede from original + paramTypes: ["number", "number"], + returnType: "function", + testCase: "5\\n4", + }, + 279: { + funName: "numSquares", + paramTypes: ["number"], + returnType: "number", + testCase: "12", + }, + 282: { + funName: "addOperators", + paramTypes: ["string", "number"], + returnType: "string[]", + testCase: '"123"\\n6', + }, + 283: { + funName: "moveZeroes", + paramTypes: ["number[]"], + returnType: "void", + testCase: "[0,1,0,3,12]", + }, + 287: { + funName: "findDuplicate", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,3,4,2,2]", + }, + 289: { + funName: "gameOfLife", + paramTypes: ["number[][]"], + returnType: "void", + testCase: "[[0,1,0],[0,0,1],[1,1,1],[0,0,0]]", + }, + 290: { + funName: "wordPattern", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"abba"\\n"dog cat cat dog"', + }, + 292: { + funName: "canWinNim", + paramTypes: ["number"], + returnType: "boolean", + testCase: "4", + }, + 295: { + funName: "MedianFinder", + paramTypes: [], + returnType: "void", + testCase: '["MedianFinder","addNum","addNum","findMedian","addNum","findMedian"]\\n[[],[1],[2],[],[3],[]]', + }, + 297: { + funName: "serialize", + paramTypes: ["TreeNode"], + returnType: "string", + testCase: "[1,2,3,null,null,4,5]", + }, + 299: { + funName: "getHint", + paramTypes: ["string", "string"], + returnType: "string", + testCase: '"1807"\\n"7810"', + }, + 300: { + funName: "lengthOfLIS", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[10,9,2,5,3,7,101,18]", + }, + 301: { + funName: "removeInvalidParentheses", + paramTypes: ["string"], + returnType: "string[]", + testCase: '"()())()"', + }, + 303: { + funName: "NumArray", + paramTypes: ["number[]"], + returnType: "void", + testCase: '["NumArray","sumRange","sumRange","sumRange"]\\n[[[-2,0,3,-5,2,-1]],[0,2],[2,5],[0,5]]', + }, + 304: { + funName: "NumMatrix", + paramTypes: ["number[][]"], + returnType: "void", + testCase: + '["NumMatrix","sumRegion","sumRegion","sumRegion"]\\n[[[[3,0,1,4,2],[5,6,3,2,1],[1,2,0,1,5],[4,1,0,1,7],[1,0,3,0,5]]],[2,1,4,3],[1,1,2,2],[1,2,2,4]]', + }, + 306: { + funName: "isAdditiveNumber", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"112358"', + }, + 307: { + funName: "NumArray", + paramTypes: ["number[]"], + returnType: "void", + testCase: '["NumArray","sumRange","update","sumRange"]\\n[[[1,3,5]],[0,2],[1,2],[0,2]]', + }, + 309: { + funName: "maxProfit", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3,0,2]", + }, + 310: { + funName: "findMinHeightTrees", + paramTypes: ["number", "number[][]"], + returnType: "number[]", + testCase: "4\\n[[1,0],[1,2],[1,3]]", + }, + 312: { + funName: "maxCoins", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,1,5,8]", + }, + 313: { + funName: "nthSuperUglyNumber", + paramTypes: ["number", "number[]"], + returnType: "number", + testCase: "12\\n[2,7,13,19]", + }, + 315: { + funName: "countSmaller", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[5,2,6,1]", + }, + 316: { + funName: "removeDuplicateLetters", + paramTypes: ["string"], + returnType: "string", + testCase: '"bcabc"', + }, + 318: { + funName: "maxProduct", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["abcw","baz","foo","bar","xtfn","abcdef"]', + }, + 319: { + funName: "bulbSwitch", + paramTypes: ["number"], + returnType: "number", + testCase: "3", + }, + 321: { + funName: "maxNumber", + paramTypes: ["number[]", "number[]", "number"], + returnType: "number[]", + testCase: "[3,4,6,5]\\n[9,1,2,5,8,3]\\n5", + }, + 322: { + funName: "coinChange", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,2,5]\\n11", + }, + 324: { + funName: "wiggleSort", + paramTypes: ["number[]"], + returnType: "void", + testCase: "[1,5,1,1,6,4]", + }, + 326: { + funName: "isPowerOfThree", + paramTypes: ["number"], + returnType: "boolean", + testCase: "27", + }, + 327: { + funName: "countRangeSum", + paramTypes: ["number[]", "number", "number"], + returnType: "number", + testCase: "[-2,5,-1]\\n-2\\n2", + }, + 328: { + funName: "oddEvenList", + paramTypes: ["ListNode"], + returnType: "ListNode", + testCase: "[1,2,3,4,5]", + }, + 329: { + funName: "longestIncreasingPath", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[9,9,4],[6,6,8],[2,1,1]]", + }, + 330: { + funName: "minPatches", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,3]\\n6", + }, + 331: { + funName: "isValidSerialization", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"9,3,4,#,#,1,#,#,2,#,6,#,#"', + }, + 332: { + funName: "findItinerary", + paramTypes: ["string[][]"], + returnType: "string[]", + testCase: '[["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]', + }, + 334: { + funName: "increasingTriplet", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,2,3,4,5]", + }, + 335: { + funName: "isSelfCrossing", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[2,1,1,2]", + }, + 336: { + funName: "palindromePairs", + paramTypes: ["string[]"], + returnType: "number[][]", + testCase: '["abcd","dcba","lls","s","sssll"]', + }, + 337: { + funName: "rob", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[3,2,3,null,3,null,1]", + }, + 338: { + funName: "countBits", + paramTypes: ["number"], + returnType: "number[]", + testCase: "2", + }, + 341: { + funName: "NestedIterator", + paramTypes: ["NestedInteger[]"], + returnType: "void", + testCase: "[[1,1],2,[1,1]]", + }, + 342: { + funName: "isPowerOfFour", + paramTypes: ["number"], + returnType: "boolean", + testCase: "16", + }, + 343: { + funName: "integerBreak", + paramTypes: ["number"], + returnType: "number", + testCase: "2", + }, + 344: { + funName: "reverseString", + paramTypes: ["character[]"], + returnType: "void", + testCase: '["h","e","l","l","o"]', + }, + 345: { + funName: "reverseVowels", + paramTypes: ["string"], + returnType: "string", + testCase: '"hello"', + }, + 347: { + funName: "topKFrequent", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[1,1,1,2,2,3]\\n2", + }, + 349: { + funName: "intersection", + paramTypes: ["number[]", "number[]"], + returnType: "number[]", + testCase: "[1,2,2,1]\\n[2,2]", + }, + 350: { + funName: "intersect", + paramTypes: ["number[]", "number[]"], + returnType: "number[]", + testCase: "[1,2,2,1]\\n[2,2]", + }, + 352: { + funName: "SummaryRanges", + paramTypes: [], + returnType: "void", + testCase: + '["SummaryRanges","addNum","getIntervals","addNum","getIntervals","addNum","getIntervals","addNum","getIntervals","addNum","getIntervals"]\\n[[],[1],[],[3],[],[7],[],[2],[],[6],[]]', + }, + 354: { + funName: "maxEnvelopes", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[5,4],[6,4],[6,7],[2,3]]", + }, + 355: { + funName: "Twitter", + paramTypes: [], + returnType: "void", + testCase: + '["Twitter","postTweet","getNewsFeed","follow","postTweet","getNewsFeed","unfollow","getNewsFeed"]\\n[[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]]', + }, + 357: { + funName: "countNumbersWithUniqueDigits", + paramTypes: ["number"], + returnType: "number", + testCase: "2", + }, + 363: { + funName: "maxSumSubmatrix", + paramTypes: ["number[][]", "number"], + returnType: "number", + testCase: "[[1,0,1],[0,-2,3]]\\n2", + }, + 365: { + funName: "canMeasureWater", + paramTypes: ["number", "number", "number"], + returnType: "boolean", + testCase: "3\\n5\\n4", + }, + 367: { + funName: "isPerfectSquare", + paramTypes: ["number"], + returnType: "boolean", + testCase: "16", + }, + 368: { + funName: "largestDivisibleSubset", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[1,2,3]", + }, + 371: { + funName: "getSum", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "1\\n2", + }, + 372: { + funName: "superPow", + paramTypes: ["number", "number[]"], + returnType: "number", + testCase: "2\\n[3]", + }, + 373: { + funName: "kSmallestPairs", + paramTypes: ["number[]", "number[]", "number"], + returnType: "number[][]", + testCase: "[1,7,11]\\n[2,4,6]\\n3", + }, + 375: { + funName: "getMoneyAmount", + paramTypes: ["number"], + returnType: "number", + testCase: "1", + }, + 376: { + funName: "wiggleMaxLength", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,7,4,9,2,5]", + }, + 377: { + funName: "combinationSum4", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,2,3]\\n4", + }, + 378: { + funName: "kthSmallest", + paramTypes: ["number[][]", "number"], + returnType: "number", + testCase: "[[1,5,9],[10,11,13],[12,13,15]]\\n8", + }, + 380: { + funName: "RandomizedSet", + paramTypes: [], + returnType: "void", + testCase: + '["RandomizedSet","insert","remove","insert","getRandom","remove","insert","getRandom"]\\n[[],[1],[2],[2],[],[1],[2],[]]', + }, + 381: { + funName: "RandomizedCollection", + paramTypes: [], + returnType: "void", + testCase: + '["RandomizedCollection","insert","insert","insert","getRandom","remove","getRandom"]\\n[[],[1],[1],[2],[],[1],[]]', + }, + 382: { + funName: "Solution", + paramTypes: ["ListNode"], + returnType: "void", + testCase: '["Solution","getRandom"]\\n[[[1,2,3]],[]]', + }, + 383: { + funName: "canConstruct", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"a"\\n"b"', + }, + 384: { + funName: "Solution", + paramTypes: ["number[]"], + returnType: "void", + testCase: '["Solution","shuffle","reset","shuffle"]\\n[[[1,2,3]],[],[],[]]', + }, + 385: { + funName: "deserialize", + paramTypes: ["string"], + returnType: "NestedInteger", + testCase: '"324"', + }, + 386: { + funName: "lexicalOrder", + paramTypes: ["number"], + returnType: "number[]", + testCase: "13", + }, + 387: { + funName: "firstUniqChar", + paramTypes: ["string"], + returnType: "number", + testCase: '"leetcode"', + }, + 388: { + funName: "lengthLongestPath", + paramTypes: ["string"], + returnType: "number", + testCase: '"dir\\\\n\\\\tsubdir1\\\\n\\\\tsubdir2\\\\n\\\\t\\\\tfile.ext"', + }, + 389: { + funName: "findTheDifference", + paramTypes: ["string", "string"], + returnType: "character", + testCase: '"abcd"\\n"abcde"', + }, + 390: { + funName: "lastRemaining", + paramTypes: ["number"], + returnType: "number", + testCase: "9", + }, + 391: { + funName: "isRectangleCover", + paramTypes: ["number[][]"], + returnType: "boolean", + testCase: "[[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]", + }, + 392: { + funName: "isSubsequence", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"abc"\\n"ahbgdc"', + }, + 393: { + funName: "validUtf8", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[197,130,1]", + }, + 394: { + funName: "decodeString", + paramTypes: ["string"], + returnType: "string", + testCase: '"3[a]2[bc]"', + }, + 395: { + funName: "longestSubstring", + paramTypes: ["string", "number"], + returnType: "number", + testCase: '"aaabb"\\n3', + }, + 396: { + funName: "maxRotateFunction", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[]", + }, + 397: { + funName: "integerReplacement", + paramTypes: ["number"], + returnType: "number", + testCase: "8", + }, + 398: { + funName: "Solution", + paramTypes: ["number[]"], + returnType: "void", + testCase: '["Solution","pick"]\\n[[[1,2,3,3,3]],[3]]', + }, + 399: { + funName: "calcEquation", + paramTypes: ["string[][]", "number[]", "string[][]"], + returnType: "number[]", + testCase: '[["a","b"],["b","c"]]\\n[2.0,3.0]\\n[["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]', + }, + 400: { + funName: "findNthDigit", + paramTypes: ["number"], + returnType: "number", + testCase: "3", + }, + 401: { + funName: "readBinaryWatch", + paramTypes: ["number"], + returnType: "string[]", + testCase: "0", + }, + 402: { + funName: "removeKdigits", + paramTypes: ["string", "number"], + returnType: "string", + testCase: '"1432219"\\n3', + }, + 403: { + funName: "canCross", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[0,1,3,4,5,7,9,10,12]", + }, + 404: { + funName: "sumOfLeftLeaves", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[3,9,20,null,null,15,7]", + }, + 405: { + funName: "toHex", + paramTypes: ["number"], + returnType: "string", + testCase: "26", + }, + 406: { + funName: "reconstructQueue", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]", + }, + 407: { + funName: "trapRainWater", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]", + }, + 409: { + funName: "longestPalindrome", + paramTypes: ["string"], + returnType: "number", + testCase: '"abccccdd"', + }, + 410: { + funName: "splitArray", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[7,2,5,10,8]\\n2", + }, + 412: { + funName: "fizzBuzz", + paramTypes: ["number"], + returnType: "string[]", + testCase: "1", + }, + 413: { + funName: "numberOfArithmeticSlices", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3,4]", + }, + 414: { + funName: "thirdMax", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,2,1]", + }, + 415: { + funName: "addStrings", + paramTypes: ["string", "string"], + returnType: "string", + testCase: '"0"\\n"0"', + }, + 416: { + funName: "canPartition", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,5,11,5]", + }, + 417: { + funName: "pacificAtlantic", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]", + }, + 419: { + funName: "countBattleships", + paramTypes: ["character[][]"], + returnType: "number", + testCase: '[["X",".",".","X"],[".",".",".","X"],[".",".",".","X"]]', + }, + 420: { + funName: "strongPasswordChecker", + paramTypes: ["string"], + returnType: "number", + testCase: '""', + }, + 421: { + funName: "findMaximumXOR", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,10,5,25,2,8]", + }, + 423: { + funName: "originalDigits", + paramTypes: ["string"], + returnType: "string", + testCase: '"owoztneoer"', + }, + 424: { + funName: "characterReplacement", + paramTypes: ["string", "number"], + returnType: "number", + testCase: '"ABAB"\\n2', + }, + 427: { + funName: "construct", + paramTypes: ["number[][]"], + returnType: "Node", + testCase: "[[0,1],[1,0]]", + }, + 429: { + funName: "levelOrder", + paramTypes: ["Node"], + returnType: "number[][]", + testCase: "[1,null,3,2,4,null,5,6]", + }, + // TODO: parse parameters + // 430: { + // funName: "flatten", + // paramTypes: ["Node"], + // returnType: "Node", + // testCase: "[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]", + // }, + 432: { + funName: "AllOne", + paramTypes: [], + returnType: "void", + testCase: '["AllOne","getMaxKey","getMinKey"]\\n[[],[],[]]', + }, + 433: { + funName: "minMutation", + paramTypes: ["string", "string", "string[]"], + returnType: "number", + testCase: '"AACCGGTT"\\n"AACCGGTA"\\n["AACCGGTA"]', + }, + 434: { + funName: "countSegments", + paramTypes: ["string"], + returnType: "number", + testCase: '"Hello, my name is John"', + }, + 435: { + funName: "eraseOverlapIntervals", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,2]]", + }, + 436: { + funName: "findRightInterval", + paramTypes: ["number[][]"], + returnType: "number[]", + testCase: "[[1,2]]", + }, + 437: { + funName: "pathSum", + paramTypes: ["TreeNode", "number"], + returnType: "number", + testCase: "[10,5,-3,3,2,null,11,3,-2,null,1]\\n8", + }, + 438: { + funName: "findAnagrams", + paramTypes: ["string", "string"], + returnType: "number[]", + testCase: '"cbaebabacd"\\n"abc"', + }, + 440: { + funName: "findKthNumber", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "13\\n2", + }, + 441: { + funName: "arrangeCoins", + paramTypes: ["number"], + returnType: "number", + testCase: "5", + }, + 442: { + funName: "findDuplicates", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[4,3,2,7,8,2,3,1]", + }, + 443: { + funName: "compress", + paramTypes: ["character[]"], + returnType: "number", + testCase: '["a","a","b","b","c","c","c"]', + }, + 445: { + funName: "addTwoNumbers", + paramTypes: ["ListNode", "ListNode"], + returnType: "ListNode", + testCase: "[7,2,4,3]\\n[5,6,4]", + }, + 446: { + funName: "numberOfArithmeticSlices", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,4,6,8,10]", + }, + 447: { + funName: "numberOfBoomerangs", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,0],[1,0],[2,0]]", + }, + 448: { + funName: "findDisappearedNumbers", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[4,3,2,7,8,2,3,1]", + }, + 449: { + funName: "serialize", + paramTypes: ["TreeNode"], + returnType: "string", + testCase: "[2,1,3]", + }, + 450: { + funName: "deleteNode", + paramTypes: ["TreeNode", "number"], + returnType: "TreeNode", + testCase: "[5,3,6,2,4,null,7]\\n3", + }, + 451: { + funName: "frequencySort", + paramTypes: ["string"], + returnType: "string", + testCase: '"tree"', + }, + 452: { + funName: "findMinArrowShots", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[10,16],[2,8],[1,6],[7,12]]", + }, + 453: { + funName: "minMoves", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3]", + }, + 454: { + funName: "fourSumCount", + paramTypes: ["number[]", "number[]", "number[]", "number[]"], + returnType: "number", + testCase: "[1,2]\\n[-2,-1]\\n[-1,2]\\n[0,2]", + }, + 455: { + funName: "findContentChildren", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[1,2,3]\\n[1,1]", + }, + 456: { + funName: "find132pattern", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,2,3,4]", + }, + 457: { + funName: "circularArrayLoop", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[2,-1,1,2,2]", + }, + 458: { + funName: "poorPigs", + paramTypes: ["number", "number", "number"], + returnType: "number", + testCase: "1000\\n15\\n60", + }, + 459: { + funName: "repeatedSubstringPattern", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"abab"', + }, + 460: { + funName: "LFUCache", + paramTypes: ["number"], + returnType: "void", + testCase: + '["LFUCache","put","put","get","put","get","get","put","get","get","get"]\\n[[2],[1,1],[2,2],[1],[3,3],[2],[3],[4,4],[1],[3],[4]]', + }, + 461: { + funName: "hammingDistance", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "1\\n4", + }, + 462: { + funName: "minMoves2", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3]", + }, + 463: { + funName: "islandPerimeter", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]", + }, + 464: { + funName: "canIWin", + paramTypes: ["number", "number"], + returnType: "boolean", + testCase: "10\\n11", + }, + 466: { + funName: "getMaxRepetitions", + paramTypes: ["string", "number", "string", "number"], + returnType: "number", + testCase: '"acb"\\n4\\n"ab"\\n2', + }, + 467: { + funName: "findSubstringInWraproundString", + paramTypes: ["string"], + returnType: "number", + testCase: '"a"', + }, + 468: { + funName: "validIPAddress", + paramTypes: ["string"], + returnType: "string", + testCase: '"172.16.254.1"', + }, + 470: { + funName: "rand10", + paramTypes: [], + returnType: "number", + testCase: "1", + }, + 472: { + funName: "findAllConcatenatedWordsInADict", + paramTypes: ["string[]"], + returnType: "string[]", + testCase: '["cat","cats","catsdogcats","dog","dogcatsdog","hippopotamuses","rat","ratcatdogcat"]', + }, + 473: { + funName: "makesquare", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,1,2,2,2]", + }, + 474: { + funName: "findMaxForm", + paramTypes: ["string[]", "number", "number"], + returnType: "number", + testCase: '["10","0001","111001","1","0"]\\n5\\n3', + }, + 475: { + funName: "findRadius", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[1,2,3]\\n[2]", + }, + 476: { + funName: "findComplement", + paramTypes: ["number"], + returnType: "number", + testCase: "5", + }, + 477: { + funName: "totalHammingDistance", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[4,14,2]", + }, + 478: { + funName: "Solution", + paramTypes: ["number", "number", "number"], + returnType: "void", + testCase: '["Solution", "randPoint", "randPoint", "randPoint"]\\n[[1.0, 0.0, 0.0], [], [], []]', + }, + 479: { + funName: "largestPalindrome", + paramTypes: ["number"], + returnType: "number", + testCase: "1", + }, + 480: { + funName: "medianSlidingWindow", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[1,3,-1,-3,5,3,6,7]\\n3", + }, + 481: { + funName: "magicalString", + paramTypes: ["number"], + returnType: "number", + testCase: "1", + }, + 482: { + funName: "licenseKeyFormatting", + paramTypes: ["string", "number"], + returnType: "string", + testCase: '"5F3Z-2e-9-w"\\n4', + }, + 483: { + funName: "smallestGoodBase", + paramTypes: ["string"], + returnType: "string", + testCase: '"13"', + }, + 485: { + funName: "findMaxConsecutiveOnes", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,0,1,1,0,1]", + }, + 486: { + funName: "PredictTheWinner", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,5,2]", + }, + 488: { + funName: "findMinStep", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"WRRBBW"\\n"RB"', + }, + 491: { + funName: "findSubsequences", + paramTypes: ["number[]"], + returnType: "number[][]", + testCase: "[4,6,7,7]", + }, + 492: { + funName: "constructRectangle", + paramTypes: ["number"], + returnType: "number[]", + testCase: "1", + }, + 493: { + funName: "reversePairs", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,3,2,3,1]", + }, + 494: { + funName: "findTargetSumWays", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,1,1,1,1]\\n3", + }, + 495: { + funName: "findPoisonedDuration", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,4]\\n2", + }, + 496: { + funName: "nextGreaterElement", + paramTypes: ["number[]", "number[]"], + returnType: "number[]", + testCase: "[4,1,2]\\n[1,3,4,2]", + }, + 497: { + funName: "Solution", + paramTypes: ["number[][]"], + returnType: "void", + testCase: '["Solution", "pick", "pick", "pick"]\\n[[[[1, 1, 5, 5]]], [], [], []]', + }, + 498: { + funName: "findDiagonalOrder", + paramTypes: ["number[][]"], + returnType: "number[]", + testCase: "[[1,2,3],[4,5,6],[7,8,9]]", + }, + 500: { + funName: "findWords", + paramTypes: ["string[]"], + returnType: "string[]", + testCase: '["Hello","Alaska","Dad","Peace"]', + }, + 501: { + funName: "findMode", + paramTypes: ["TreeNode"], + returnType: "number[]", + testCase: "[1,null,2,2]", + }, + 502: { + funName: "findMaximizedCapital", + paramTypes: ["number", "number", "number[]", "number[]"], + returnType: "number", + testCase: "2\\n0\\n[1,2,3]\\n[0,1,1]", + }, + 503: { + funName: "nextGreaterElements", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[1,2,1]", + }, + 504: { + funName: "convertToBase7", + paramTypes: ["number"], + returnType: "string", + testCase: "100", + }, + 506: { + funName: "findRelativeRanks", + paramTypes: ["number[]"], + returnType: "string[]", + testCase: "[5,4,3,2,1]", + }, + 507: { + funName: "checkPerfectNumber", + paramTypes: ["number"], + returnType: "boolean", + testCase: "28", + }, + 508: { + funName: "findFrequentTreeSum", + paramTypes: ["TreeNode"], + returnType: "number[]", + testCase: "[5,2,-3]", + }, + 509: { + funName: "fib", + paramTypes: ["number"], + returnType: "number", + testCase: "2", + }, + 513: { + funName: "findBottomLeftValue", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[2,1,3]", + }, + 514: { + funName: "findRotateSteps", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"godding"\\n"gd"', + }, + 515: { + funName: "largestValues", + paramTypes: ["TreeNode"], + returnType: "number[]", + testCase: "[1,3,2,5,3,null,9]", + }, + 516: { + funName: "longestPalindromeSubseq", + paramTypes: ["string"], + returnType: "number", + testCase: '"bbbab"', + }, + 517: { + funName: "findMinMoves", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,0,5]", + }, + 518: { + funName: "change", + paramTypes: ["number", "number[]"], + returnType: "number", + testCase: "5\\n[1,2,5]", + }, + 519: { + funName: "Solution", + paramTypes: ["number", "number"], + returnType: "void", + testCase: '["Solution", "flip", "flip", "flip", "flip"]\\n[[2, 2], [], [], [], []]', + }, + 520: { + funName: "detectCapitalUse", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"USA"', + }, + 521: { + funName: "findLUSlength", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"aba"\\n"cdc"', + }, + 522: { + funName: "findLUSlength", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["aba","cdc","eae"]', + }, + 523: { + funName: "checkSubarraySum", + paramTypes: ["number[]", "number"], + returnType: "boolean", + testCase: "[23,2,4,6,7]\\n6", + }, + 524: { + funName: "findLongestWord", + paramTypes: ["string", "string[]"], + returnType: "string", + testCase: '"abpcplea"\\n["ale","apple","monkey","plea"]', + }, + 525: { + funName: "findMaxLength", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[0,1]", + }, + 526: { + funName: "countArrangement", + paramTypes: ["number"], + returnType: "number", + testCase: "2", + }, + 528: { + funName: "Solution", + paramTypes: ["number[]"], + returnType: "void", + testCase: '["Solution", "pickIndex"]\\n[[[1]], []]', + }, + 529: { + funName: "updateBoard", + paramTypes: ["character[][]", "number[]"], + returnType: "character[][]", + testCase: '[["E","E","E","E","E"],["E","E","M","E","E"],["E","E","E","E","E"],["E","E","E","E","E"]]\\n[3,0]', + }, + 530: { + funName: "getMinimumDifference", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[1,null,3,2]", + }, + 532: { + funName: "findPairs", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[3,1,4,1,5]\\n2", + }, + 535: { + funName: "encode", + paramTypes: ["string"], + returnType: "string", + testCase: '"https://leetcode.com/problems/design-tinyurl"', + }, + 537: { + funName: "complexNumberMultiply", + paramTypes: ["string", "string"], + returnType: "string", + testCase: '"1+1i"\\n"1+1i"', + }, + 538: { + funName: "convertBST", + paramTypes: ["TreeNode"], + returnType: "TreeNode", + testCase: "[5,2,13]", + }, + 539: { + funName: "findMinDifference", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["23:59","00:00"]', + }, + 540: { + funName: "singleNonDuplicate", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,1,2,3,3,4,4,8,8]", + }, + 541: { + funName: "reverseStr", + paramTypes: ["string", "number"], + returnType: "string", + testCase: '"abcdefg"\\n2', + }, + 542: { + funName: "updateMatrix", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[0,0,0],[0,1,0],[0,0,0]]", + }, + 543: { + funName: "diameterOfBinaryTree", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[1,2,3,4,5]", + }, + 546: { + funName: "removeBoxes", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,3,2,2,2,3,4,3,1]", + }, + 547: { + funName: "findCircleNum", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,1,0],[1,1,0],[0,0,1]]", + }, + 551: { + funName: "checkRecord", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"PPALLP"', + }, + 552: { + funName: "checkRecord", + paramTypes: ["number"], + returnType: "number", + testCase: "1", + }, + 553: { + funName: "optimalDivision", + paramTypes: ["number[]"], + returnType: "string", + testCase: "[1000,100,10,2]", + }, + 554: { + funName: "leastBricks", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1]]", + }, + 556: { + funName: "nextGreaterElement", + paramTypes: ["number"], + returnType: "number", + testCase: "12", + }, + 557: { + funName: "reverseWords", + paramTypes: ["string"], + returnType: "string", + testCase: '"Let\\', + }, + // TODO: parse parameters + // 558: { + // funName: "intersect", + // paramTypes: ["Node", "Node"], + // returnType: "Node", + // testCase: + // "[[0,1],[1,1],[1,1],[1,0],[1,0]]\\n[[0,1],[1,1],[0,1],[1,1],[1,0],null,null,null,null,[1,0],[1,0],[1,1],[1,1]]", + // }, + 559: { + funName: "maxDepth", + paramTypes: ["Node"], + returnType: "number", + testCase: "[1,null,3,2,4,null,5,6]", + }, + 560: { + funName: "subarraySum", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,1,1]\\n2", + }, + 561: { + funName: "arrayPairSum", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,4,3,2]", + }, + 563: { + funName: "findTilt", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[1,2,3]", + }, + 564: { + funName: "nearestPalindromic", + paramTypes: ["string"], + returnType: "string", + testCase: '"1"', + }, + 565: { + funName: "arrayNesting", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[5,4,0,3,1,6,2]", + }, + 566: { + funName: "matrixReshape", + paramTypes: ["number[][]", "number", "number"], + returnType: "number[][]", + testCase: "[[1,2],[3,4]]\\n1\\n4", + }, + 567: { + funName: "checkInclusion", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"ab"\\n"eidbaooo"', + }, + 572: { + funName: "isSubtree", + paramTypes: ["TreeNode", "TreeNode"], + returnType: "boolean", + testCase: "[3,4,5,1,2]\\n[4,1,2]", + }, + 575: { + funName: "distributeCandies", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,1,2,2,3,3]", + }, + 576: { + funName: "findPaths", + paramTypes: ["number", "number", "number", "number", "number"], + returnType: "number", + testCase: "2\\n2\\n2\\n0\\n0", + }, + 581: { + funName: "findUnsortedSubarray", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,6,4,8,10,9,15]", + }, + 583: { + funName: "minDistance", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"sea"\\n"eat"', + }, + 587: { + funName: "outerTrees", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]", + }, + 589: { + funName: "preorder", + paramTypes: ["Node"], + returnType: "number[]", + testCase: "[1,null,3,2,4,null,5,6]", + }, + 590: { + funName: "postorder", + paramTypes: ["Node"], + returnType: "number[]", + testCase: "[1,null,3,2,4,null,5,6]", + }, + 591: { + funName: "isValid", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"
This is the first line ]]>
"', + }, + 592: { + funName: "fractionAddition", + paramTypes: ["string"], + returnType: "string", + testCase: '"-1/2+1/2"', + }, + 593: { + funName: "validSquare", + paramTypes: ["number[]", "number[]", "number[]", "number[]"], + returnType: "boolean", + testCase: "[0,0]\\n[1,1]\\n[1,0]\\n[0,1]", + }, + 594: { + funName: "findLHS", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,3,2,2,5,2,3,7]", + }, + 598: { + funName: "maxCount", + paramTypes: ["number", "number", "number[][]"], + returnType: "number", + testCase: "3\\n3\\n[[2,2],[3,3]]", + }, + 599: { + funName: "findRestaurant", + paramTypes: ["string[]", "string[]"], + returnType: "string[]", + testCase: + '["Shogun","Tapioca Express","Burger King","KFC"]\\n["Piatti","The Grill at Torrey Pines","Hungry Hunter Steakhouse","Shogun"]', + }, + 600: { + funName: "findIntegers", + paramTypes: ["number"], + returnType: "number", + testCase: "1", + }, + 605: { + funName: "canPlaceFlowers", + paramTypes: ["number[]", "number"], + returnType: "boolean", + testCase: "[1,0,0,0,1]\\n1", + }, + 606: { + funName: "tree2str", + paramTypes: ["TreeNode"], + returnType: "string", + testCase: "[1,2,3,4]", + }, + 609: { + funName: "findDuplicate", + paramTypes: ["string[]"], + returnType: "string[][]", + testCase: '["root/a 1.txt(abcd) 2.txt(efgh)","root/c 3.txt(abcd)","root/c/d 4.txt(efgh)","root 4.txt(efgh)"]', + }, + 611: { + funName: "triangleNumber", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,2,3,4]", + }, + 617: { + funName: "mergeTrees", + paramTypes: ["TreeNode", "TreeNode"], + returnType: "TreeNode", + testCase: "[1,3,2,5]\\n[2,1,3,null,4,null,7]", + }, + 621: { + funName: "leastInterval", + paramTypes: ["character[]", "number"], + returnType: "number", + testCase: '["A","A","A","B","B","B"]\\n2', + }, + 622: { + funName: "MyCircularQueue", + paramTypes: ["number"], + returnType: "void", + testCase: + '["MyCircularQueue","enQueue","enQueue","enQueue","enQueue","Rear","isFull","deQueue","enQueue","Rear"]\\n[[3],[1],[2],[3],[4],[],[],[],[4],[]]', + }, + 623: { + funName: "addOneRow", + paramTypes: ["TreeNode", "number", "number"], + returnType: "TreeNode", + testCase: "[4,2,6,3,1,5]\\n1\\n2", + }, + 628: { + funName: "maximumProduct", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3]", + }, + 629: { + funName: "kInversePairs", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "3\\n0", + }, + 630: { + funName: "scheduleCourse", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[100,200],[200,1300],[1000,1250],[2000,3200]]", + }, + 632: { + funName: "smallestRange", + paramTypes: ["number[][]"], + returnType: "number[]", + testCase: "[[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]", + }, + 633: { + funName: "judgeSquareSum", + paramTypes: ["number"], + returnType: "boolean", + testCase: "5", + }, + 636: { + funName: "exclusiveTime", + paramTypes: ["number", "string[]"], + returnType: "number[]", + testCase: '2\\n["0:start:0","1:start:2","1:end:5","0:end:6"]', + }, + 637: { + funName: "averageOfLevels", + paramTypes: ["TreeNode"], + returnType: "number[]", + testCase: "[3,9,20,15,7]", + }, + 638: { + funName: "shoppingOffers", + paramTypes: ["number[]", "number[][]", "number[]"], + returnType: "number", + testCase: "[2,5]\\n[[3,0,5],[1,2,10]]\\n[3,2]", + }, + 639: { + funName: "numDecodings", + paramTypes: ["string"], + returnType: "number", + testCase: '"*"', + }, + 640: { + funName: "solveEquation", + paramTypes: ["string"], + returnType: "string", + testCase: '"x+5-3+x=6+x-2"', + }, + 641: { + funName: "MyCircularDeque", + paramTypes: ["number"], + returnType: "void", + testCase: + '["MyCircularDeque","insertLast","insertLast","insertFront","insertFront","getRear","isFull","deleteLast","insertFront","getFront"]\\n[[3],[1],[2],[3],[4],[],[],[],[4],[]]', + }, + 643: { + funName: "findMaxAverage", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,12,-5,-6,50,3]\\n4", + }, + 645: { + funName: "findErrorNums", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[1,2,2,4]", + }, + 646: { + funName: "findLongestChain", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,2], [2,3], [3,4]]", + }, + 647: { + funName: "countSubstrings", + paramTypes: ["string"], + returnType: "number", + testCase: '"abc"', + }, + 648: { + funName: "replaceWords", + paramTypes: ["string[]", "string"], + returnType: "string", + testCase: '["cat", "bat", "rat"]\\n"the cattle was rattled by the battery"', + }, + 649: { + funName: "predictPartyVictory", + paramTypes: ["string"], + returnType: "string", + testCase: '"RD"', + }, + 650: { + funName: "minSteps", + paramTypes: ["number"], + returnType: "number", + testCase: "3", + }, + 652: { + funName: "findDuplicateSubtrees", + paramTypes: ["TreeNode"], + returnType: "TreeNode[]", + testCase: "[1,2,3,4,null,2,4,null,null,4]", + }, + 653: { + funName: "findTarget", + paramTypes: ["TreeNode", "number"], + returnType: "boolean", + testCase: "[5,3,6,2,4,null,7]\\n9", + }, + 654: { + funName: "constructMaximumBinaryTree", + paramTypes: ["number[]"], + returnType: "TreeNode", + testCase: "[3,2,1,6,0,5]", + }, + 655: { + funName: "printTree", + paramTypes: ["TreeNode"], + returnType: "string[][]", + testCase: "[1,2]", + }, + 657: { + funName: "judgeCircle", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"UD"', + }, + 658: { + funName: "findClosestElements", + paramTypes: ["number[]", "number", "number"], + returnType: "number[]", + testCase: "[1,2,3,4,5]\\n4\\n3", + }, + 659: { + funName: "isPossible", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,2,3,3,4,5]", + }, + 661: { + funName: "imageSmoother", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[1,1,1],[1,0,1],[1,1,1]]", + }, + 662: { + funName: "widthOfBinaryTree", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[1,3,2,5,3,null,9]", + }, + 664: { + funName: "strangePrinter", + paramTypes: ["string"], + returnType: "number", + testCase: '"aaabbb"', + }, + 665: { + funName: "checkPossibility", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[4,2,3]", + }, + 667: { + funName: "constructArray", + paramTypes: ["number", "number"], + returnType: "number[]", + testCase: "3\\n2", + }, + 668: { + funName: "findKthNumber", + paramTypes: ["number", "number", "number"], + returnType: "number", + testCase: "3\\n3\\n5", + }, + 669: { + funName: "trimBST", + paramTypes: ["TreeNode", "number", "number"], + returnType: "TreeNode", + testCase: "[1,0,2]\\n1\\n2", + }, + 670: { + funName: "maximumSwap", + paramTypes: ["number"], + returnType: "number", + testCase: "2736", + }, + 671: { + funName: "findSecondMinimumValue", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[2,2,5,null,null,5,7]", + }, + 672: { + funName: "flipLights", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "1\\n1", + }, + 673: { + funName: "findNumberOfLIS", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,3,5,4,7]", + }, + 674: { + funName: "findLengthOfLCIS", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,3,5,4,7]", + }, + 675: { + funName: "cutOffTree", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,2,3],[0,0,4],[7,6,5]]", + }, + 676: { + funName: "MagicDictionary", + paramTypes: [], + returnType: "void", + testCase: + '["MagicDictionary", "buildDict", "search", "search", "search", "search"]\\n[[], [["hello","leetcode"]], ["hello"], ["hhllo"], ["hell"], ["leetcoded"]]', + }, + 677: { + funName: "MapSum", + paramTypes: [], + returnType: "void", + testCase: '["MapSum", "insert", "sum", "insert", "sum"]\\n[[], ["apple",3], ["ap"], ["app",2], ["ap"]]', + }, + 678: { + funName: "checkValidString", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"()"', + }, + 679: { + funName: "judgePoint24", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[4,1,8,7]", + }, + 680: { + funName: "validPalindrome", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"aba"', + }, + 682: { + funName: "calPoints", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["5","2","C","D","+"]', + }, + 684: { + funName: "findRedundantConnection", + paramTypes: ["number[][]"], + returnType: "number[]", + testCase: "[[1,2],[1,3],[2,3]]", + }, + 685: { + funName: "findRedundantDirectedConnection", + paramTypes: ["number[][]"], + returnType: "number[]", + testCase: "[[1,2],[1,3],[2,3]]", + }, + 686: { + funName: "repeatedStringMatch", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"abcd"\\n"cdabcdab"', + }, + 687: { + funName: "longestUnivaluePath", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[5,4,5,1,1,5]", + }, + 688: { + funName: "knightProbability", + paramTypes: ["number", "number", "number", "number"], + returnType: "number", + testCase: "3\\n2\\n0\\n0", + }, + 689: { + funName: "maxSumOfThreeSubarrays", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[1,2,1,2,6,7,5,1]\\n2", + }, + 691: { + funName: "minStickers", + paramTypes: ["string[]", "string"], + returnType: "number", + testCase: '["with","example","science"]\\n"thehat"', + }, + 692: { + funName: "topKFrequent", + paramTypes: ["string[]", "number"], + returnType: "string[]", + testCase: '["i", "love", "leetcode", "i", "love", "coding"]\\n2', + }, + 693: { + funName: "hasAlternatingBits", + paramTypes: ["number"], + returnType: "boolean", + testCase: "5", + }, + 695: { + funName: "maxAreaOfIsland", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]", + }, + 696: { + funName: "countBinarySubstrings", + paramTypes: ["string"], + returnType: "number", + testCase: '"00110"', + }, + 697: { + funName: "findShortestSubArray", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,2,3,1]", + }, + 698: { + funName: "canPartitionKSubsets", + paramTypes: ["number[]", "number"], + returnType: "boolean", + testCase: "[4,3,2,3,5,2,1]\\n4", + }, + 699: { + funName: "fallingSquares", + paramTypes: ["number[][]"], + returnType: "number[]", + testCase: "[[1,2],[2,3],[6,1]]", + }, + 700: { + funName: "searchBST", + paramTypes: ["TreeNode", "number"], + returnType: "TreeNode", + testCase: "[4,2,7,1,3]\\n2", + }, + 701: { + funName: "insertIntoBST", + paramTypes: ["TreeNode", "number"], + returnType: "TreeNode", + testCase: "[4,2,7,1,3]\\n5", + }, + 703: { + funName: "KthLargest", + paramTypes: ["number", "number[]"], + returnType: "void", + testCase: '["KthLargest","add","add","add","add","add"]\\n[[3,[4,5,8,2]],[3],[5],[10],[9],[4]]', + }, + 704: { + funName: "search", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[-1,0,3,5,9,12]\\n9", + }, + 705: { + funName: "MyHashSet", + paramTypes: [], + returnType: "void", + testCase: + '["MyHashSet","add","add","contains","contains","add","contains","remove","contains"]\\n[[],[1],[2],[1],[3],[2],[2],[2],[2]]', + }, + 706: { + funName: "MyHashMap", + paramTypes: [], + returnType: "void", + testCase: + '["MyHashMap","put","put","get","get","put","get", "remove", "get"]\\n[[],[1,1],[2,2],[1],[3],[2,1],[2],[2],[2]]', + }, + 707: { + funName: "MyLinkedList", + paramTypes: [], + returnType: "void", + testCase: + '["MyLinkedList","addAtHead","addAtTail","addAtIndex","get","deleteAtIndex","get"]\\n[[],[1],[3],[1,2],[1],[1],[1]]', + }, + 709: { + funName: "toLowerCase", + paramTypes: ["string"], + returnType: "string", + testCase: '"Hello"', + }, + 710: { + funName: "Solution", + paramTypes: ["number", "number[]"], + returnType: "void", + testCase: '["Solution", "pick", "pick", "pick"]\\n[[1, []], [], [], []]', + }, + 712: { + funName: "minimumDeleteSum", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"sea"\\n"eat"', + }, + 713: { + funName: "numSubarrayProductLessThanK", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[10,5,2,6]\\n100", + }, + 714: { + funName: "maxProfit", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,3,2,8,4,9]\\n2", + }, + 715: { + funName: "RangeModule", + paramTypes: [], + returnType: "void", + testCase: + '["RangeModule","addRange","removeRange","queryRange","queryRange","queryRange"]\\n[[],[10,20],[14,16],[10,14],[13,15],[16,17]]', + }, + 717: { + funName: "isOneBitCharacter", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,0,0]", + }, + 718: { + funName: "findLength", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[1,2,3,2,1]\\n[3,2,1,4,7]", + }, + 719: { + funName: "smallestDistancePair", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,3,1]\\n1", + }, + 720: { + funName: "longestWord", + paramTypes: ["string[]"], + returnType: "string", + testCase: '["w","wo","wor","worl","world"]', + }, + 721: { + funName: "accountsMerge", + paramTypes: ["string[][]"], + returnType: "string[][]", + testCase: + '[["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]', + }, + 722: { + funName: "removeComments", + paramTypes: ["string[]"], + returnType: "string[]", + testCase: + '["/*Test program */", "int main()", "{ ", " // variable declaration ", "int a, b, c;", "/* This is a test", " multiline ", " comment for ", " testing */", "a = b + c;", "}"]', + }, + 724: { + funName: "pivotIndex", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,7,3,6,5,6]", + }, + 725: { + funName: "splitListToParts", + paramTypes: ["ListNode", "number"], + returnType: "ListNode[]", + testCase: "[1,2,3,4]\\n5", + }, + 726: { + funName: "countOfAtoms", + paramTypes: ["string"], + returnType: "string", + testCase: '"H2O"', + }, + 728: { + funName: "selfDividingNumbers", + paramTypes: ["number", "number"], + returnType: "number[]", + testCase: "1\\n22", + }, + 729: { + funName: "MyCalendar", + paramTypes: [], + returnType: "void", + testCase: '["MyCalendar","book","book","book"]\\n[[],[10,20],[15,25],[20,30]]', + }, + 730: { + funName: "countPalindromicSubsequences", + paramTypes: ["string"], + returnType: "number", + testCase: '"bccb"', + }, + 731: { + funName: "MyCalendarTwo", + paramTypes: [], + returnType: "void", + testCase: + '["MyCalendarTwo","book","book","book","book","book","book"]\\n[[],[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]', + }, + 732: { + funName: "MyCalendarThree", + paramTypes: [], + returnType: "void", + testCase: + '["MyCalendarThree","book","book","book","book","book","book"]\\n[[],[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]', + }, + 733: { + funName: "floodFill", + paramTypes: ["number[][]", "number", "number", "number"], + returnType: "number[][]", + testCase: "[[1,1,1],[1,1,0],[1,0,1]]\\n1\\n1\\n2", + }, + 735: { + funName: "asteroidCollision", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[5,10,-5]", + }, + 736: { + funName: "evaluate", + paramTypes: ["string"], + returnType: "number", + testCase: '"(add 1 2)"', + }, + 738: { + funName: "monotoneIncreasingDigits", + paramTypes: ["number"], + returnType: "number", + testCase: "10", + }, + 739: { + funName: "dailyTemperatures", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[73,74,75,71,69,72,76,73]", + }, + 740: { + funName: "deleteAndEarn", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,4,2]", + }, + 741: { + funName: "cherryPickup", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,1,-1],[1,0,-1],[1,1,1]]", + }, + 743: { + funName: "networkDelayTime", + paramTypes: ["number[][]", "number", "number"], + returnType: "number", + testCase: "[[2,1,1],[2,3,1],[3,4,1]]\\n4\\n2", + }, + 744: { + funName: "nextGreatestLetter", + paramTypes: ["character[]", "character"], + returnType: "character", + testCase: '["c","f","j"]\\n"a"', + }, + 745: { + funName: "WordFilter", + paramTypes: ["string[]"], + returnType: "void", + testCase: '["WordFilter","f"]\\n[[["apple"]],["a","e"]]', + }, + 746: { + funName: "minCostClimbingStairs", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[0,0,0,0]", + }, + 747: { + funName: "dominantIndex", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[0,0,0,1]", + }, + 748: { + funName: "shortestCompletingWord", + paramTypes: ["string", "string[]"], + returnType: "string", + testCase: '"1s3 PSt"\\n["step","steps","stripe","stepple"]', + }, + 749: { + funName: "containVirus", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,1,0,0,0,0,0,1],[0,1,0,0,0,0,0,1],[0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0]]", + }, + 752: { + funName: "openLock", + paramTypes: ["string[]", "string"], + returnType: "number", + testCase: '["0201","0101","0102","1212","2002"]\\n"0202"', + }, + 753: { + funName: "crackSafe", + paramTypes: ["number", "number"], + returnType: "string", + testCase: "1\\n1", + }, + 754: { + funName: "reachNumber", + paramTypes: ["number"], + returnType: "number", + testCase: "1", + }, + 756: { + funName: "pyramidTransition", + paramTypes: ["string", "string[]"], + returnType: "boolean", + testCase: '"ABC"\\n["ABD","BCE","DEF","FFF"]', + }, + 757: { + funName: "intersectionSizeTwo", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,3],[1,4],[2,5],[3,5]]", + }, + 761: { + funName: "makeLargestSpecial", + paramTypes: ["string"], + returnType: "string", + testCase: '"11011000"', + }, + 762: { + funName: "countPrimeSetBits", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "842\\n888", + }, + 763: { + funName: "partitionLabels", + paramTypes: ["string"], + returnType: "number[]", + testCase: '"ababcbacadefegdehijhklij"', + }, + 764: { + funName: "orderOfLargestPlusSign", + paramTypes: ["number", "number[][]"], + returnType: "number", + testCase: "5\\n[[4,2]]", + }, + 765: { + funName: "minSwapsCouples", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[0,2,1,3]", + }, + 766: { + funName: "isToeplitzMatrix", + paramTypes: ["number[][]"], + returnType: "boolean", + testCase: "[[1,2,3,4],[5,1,2,3],[9,5,1,2]]", + }, + 767: { + funName: "reorganizeString", + paramTypes: ["string"], + returnType: "string", + testCase: '"aab"', + }, + 768: { + funName: "maxChunksToSorted", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[5,4,3,2,1]", + }, + 769: { + funName: "maxChunksToSorted", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[4,3,2,1,0]", + }, + 770: { + funName: "basicCalculatorIV", + paramTypes: ["string", "string[]", "number[]"], + returnType: "string[]", + testCase: '"e + 8 - a + 5"\\n["e"]\\n[1]', + }, + 771: { + funName: "numJewelsInStones", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"aA"\\n"aAAbbbb"', + }, + 773: { + funName: "slidingPuzzle", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,2,3],[4,0,5]]", + }, + 775: { + funName: "isIdealPermutation", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[0]", + }, + 777: { + funName: "canTransform", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"X"\\n"L"', + }, + 778: { + funName: "swimInWater", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,2],[1,3]]", + }, + 779: { + funName: "kthGrammar", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "1\\n1", + }, + 780: { + funName: "reachingPoints", + paramTypes: ["number", "number", "number", "number"], + returnType: "boolean", + testCase: "9\\n5\\n12\\n8", + }, + 781: { + funName: "numRabbits", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,0,1,0,0]", + }, + 782: { + funName: "movesToChessboard", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]]", + }, + 783: { + funName: "minDiffInBST", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[4,2,6,1,3,null,null]", + }, + 784: { + funName: "letterCasePermutation", + paramTypes: ["string"], + returnType: "string[]", + testCase: '"a1b2"', + }, + 785: { + funName: "isBipartite", + paramTypes: ["number[][]"], + returnType: "boolean", + testCase: "[[1,3],[0,2],[1,3],[0,2]]", + }, + 786: { + funName: "kthSmallestPrimeFraction", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[1,2,3,5]\\n3", + }, + 787: { + funName: "findCheapestPrice", + paramTypes: ["number", "number[][]", "number", "number", "number"], + returnType: "number", + testCase: "3\\n[[0,1,100],[1,2,100],[0,2,500]]\\n0\\n2\\n1", + }, + 788: { + funName: "rotatedDigits", + paramTypes: ["number"], + returnType: "number", + testCase: "10", + }, + 789: { + funName: "escapeGhosts", + paramTypes: ["number[][]", "number[]"], + returnType: "boolean", + testCase: "[[1,0],[0,3]]\\n[0,1]", + }, + 790: { + funName: "numTilings", + paramTypes: ["number"], + returnType: "number", + testCase: "3", + }, + 791: { + funName: "customSortString", + paramTypes: ["string", "string"], + returnType: "string", + testCase: '"cba"\\n"abcd"', + }, + 792: { + funName: "numMatchingSubseq", + paramTypes: ["string", "string[]"], + returnType: "number", + testCase: '"abcde"\\n["a","bb","acd","ace"]', + }, + 793: { + funName: "preimageSizeFZF", + paramTypes: ["number"], + returnType: "number", + testCase: "0", + }, + 794: { + funName: "validTicTacToe", + paramTypes: ["string[]"], + returnType: "boolean", + testCase: '["O "," "," "]', + }, + 795: { + funName: "numSubarrayBoundedMax", + paramTypes: ["number[]", "number", "number"], + returnType: "number", + testCase: "[2,1,4,3]\\n2\\n3", + }, + 796: { + funName: "rotateString", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"abcde"\\n"cdeab"', + }, + 797: { + funName: "allPathsSourceTarget", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[1,2],[3],[3],[]]", + }, + 798: { + funName: "bestRotation", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,3,1,4,0]", + }, + 799: { + funName: "champagneTower", + paramTypes: ["number", "number", "number"], + returnType: "number", + testCase: "1\\n1\\n1", + }, + 801: { + funName: "minSwap", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[1,3,5,4]\\n[1,2,3,7]", + }, + 802: { + funName: "eventualSafeNodes", + paramTypes: ["number[][]"], + returnType: "number[]", + testCase: "[[1,2],[2,3],[5],[0],[5],[],[]]", + }, + 803: { + funName: "hitBricks", + paramTypes: ["number[][]", "number[][]"], + returnType: "number[]", + testCase: "[[1,0,0,0],[1,1,1,0]]\\n[[1,0]]", + }, + 804: { + funName: "uniqueMorseRepresentations", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["gin", "zen", "gig", "msg"]', + }, + 805: { + funName: "splitArraySameAverage", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,2,3,4,5,6,7,8]", + }, + 806: { + funName: "numberOfLines", + paramTypes: ["number[]", "string"], + returnType: "number[]", + testCase: + '[10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]\\n"abcdefghijklmnopqrstuvwxyz"', + }, + 807: { + funName: "maxIncreaseKeepingSkyline", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]", + }, + 808: { + funName: "soupServings", + paramTypes: ["number"], + returnType: "number", + testCase: "50", + }, + 809: { + funName: "expressiveWords", + paramTypes: ["string", "string[]"], + returnType: "number", + testCase: '"heeellooo"\\n["hello", "hi", "helo"]', + }, + 810: { + funName: "xorGame", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,1,2]", + }, + 811: { + funName: "subdomainVisits", + paramTypes: ["string[]"], + returnType: "string[]", + testCase: '["9001 discuss.leetcode.com"]', + }, + 812: { + funName: "largestTriangleArea", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,0],[0,1],[1,0],[0,2],[2,0]]", + }, + 813: { + funName: "largestSumOfAverages", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[9,1,2,3,9]\\n3", + }, + 814: { + funName: "pruneTree", + paramTypes: ["TreeNode"], + returnType: "TreeNode", + testCase: "[1,null,0,0,1]", + }, + 815: { + funName: "numBusesToDestination", + paramTypes: ["number[][]", "number", "number"], + returnType: "number", + testCase: "[[1,2,7],[3,6,7]]\\n1\\n6", + }, + 816: { + funName: "ambiguousCoordinates", + paramTypes: ["string"], + returnType: "string[]", + testCase: '"(123)"', + }, + 817: { + funName: "numComponents", + paramTypes: ["ListNode", "number[]"], + returnType: "number", + testCase: "[0,1,2,3]\\n[0,1,3]", + }, + 818: { + funName: "racecar", + paramTypes: ["number"], + returnType: "number", + testCase: "3", + }, + 819: { + funName: "mostCommonWord", + paramTypes: ["string", "string[]"], + returnType: "string", + testCase: '"Bob hit a ball, the hit BALL flew far after it was hit."\\n["hit"]', + }, + 820: { + funName: "minimumLengthEncoding", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["time", "me", "bell"]', + }, + 821: { + funName: "shortestToChar", + paramTypes: ["string", "character"], + returnType: "number[]", + testCase: '"loveleetcode"\\n"e"', + }, + 822: { + funName: "flipgame", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[1,2,4,4,7]\\n[1,3,4,1,3]", + }, + 823: { + funName: "numFactoredBinaryTrees", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,4]", + }, + 824: { + funName: "toGoatLatin", + paramTypes: ["string"], + returnType: "string", + testCase: '"I speak Goat Latin"', + }, + 825: { + funName: "numFriendRequests", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[16,16]", + }, + 826: { + funName: "maxProfitAssignment", + paramTypes: ["number[]", "number[]", "number[]"], + returnType: "number", + testCase: "[2,4,6,8,10]\\n[10,20,30,40,50]\\n[4,5,6,7]", + }, + 827: { + funName: "largestIsland", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,0],[0,1]]", + }, + 828: { + funName: "uniqueLetterString", + paramTypes: ["string"], + returnType: "number", + testCase: '"ABC"', + }, + 829: { + funName: "consecutiveNumbersSum", + paramTypes: ["number"], + returnType: "number", + testCase: "5", + }, + 830: { + funName: "largeGroupPositions", + paramTypes: ["string"], + returnType: "number[][]", + testCase: '"abbxxxxzzy"', + }, + 831: { + funName: "maskPII", + paramTypes: ["string"], + returnType: "string", + testCase: '"LeetCode@LeetCode.com"', + }, + 832: { + funName: "flipAndInvertImage", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[1,1,0],[1,0,1],[0,0,0]]", + }, + 833: { + funName: "findReplaceString", + paramTypes: ["string", "number[]", "string[]", "string[]"], + returnType: "string", + testCase: '"abcd"\\n[0, 2]\\n["a", "cd"]\\n["eee", "ffff"]', + }, + 834: { + funName: "sumOfDistancesInTree", + paramTypes: ["number", "number[][]"], + returnType: "number[]", + testCase: "6\\n[[0,1],[0,2],[2,3],[2,4],[2,5]]", + }, + 835: { + funName: "largestOverlap", + paramTypes: ["number[][]", "number[][]"], + returnType: "number", + testCase: "[[1,1,0],[0,1,0],[0,1,0]]\\n[[0,0,0],[0,1,1],[0,0,1]]", + }, + 836: { + funName: "isRectangleOverlap", + paramTypes: ["number[]", "number[]"], + returnType: "boolean", + testCase: "[0,0,2,2]\\n[1,1,3,3]", + }, + 837: { + funName: "new21Game", + paramTypes: ["number", "number", "number"], + returnType: "number", + testCase: "10\\n1\\n10", + }, + 838: { + funName: "pushDominoes", + paramTypes: ["string"], + returnType: "string", + testCase: '".L.R...LR..L.."', + }, + 839: { + funName: "numSimilarGroups", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["tars","rats","arts","star"]', + }, + 840: { + funName: "numMagicSquaresInside", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[4,3,8,4],[9,5,1,9],[2,7,6,2]]", + }, + 841: { + funName: "canVisitAllRooms", + paramTypes: ["number[][]"], + returnType: "boolean", + testCase: "[[1],[2],[3],[]]", + }, + 842: { + funName: "splitIntoFibonacci", + paramTypes: ["string"], + returnType: "number[]", + testCase: '"123456579"', + }, + 843: { + funName: "findSecretWord", + // changede from original + paramTypes: ["string", "string[]", "number"], + returnType: "void", + testCase: '"acckzz"\\n["acckzz","ccbazz","eiowzz","abcczz"]\\n10', + }, + 844: { + funName: "backspaceCompare", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"ab#c"\\n"ad#c"', + }, + 845: { + funName: "longestMountain", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,1,4,7,3,2,5]", + }, + 846: { + funName: "isNStraightHand", + paramTypes: ["number[]", "number"], + returnType: "boolean", + testCase: "[1,2,3,6,2,3,4,7,8]\\n3", + }, + 847: { + funName: "shortestPathLength", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,2,3],[0],[0],[0]]", + }, + 848: { + funName: "shiftingLetters", + paramTypes: ["string", "number[]"], + returnType: "string", + testCase: '"abc"\\n[3,5,9]', + }, + 849: { + funName: "maxDistToClosest", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,0,0,0,1,0,1]", + }, + 850: { + funName: "rectangleArea", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,0,2,2],[1,0,2,3],[1,0,3,1]]", + }, + 851: { + funName: "loudAndRich", + paramTypes: ["number[][]", "number[]"], + returnType: "number[]", + testCase: "[[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]]\\n[3,2,5,4,6,1,7,0]", + }, + 852: { + funName: "peakIndexInMountainArray", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[0,1,0]", + }, + 853: { + funName: "carFleet", + paramTypes: ["number", "number[]", "number[]"], + returnType: "number", + testCase: "12\\n[10,8,0,5,3]\\n[2,4,1,1,3]", + }, + 854: { + funName: "kSimilarity", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"ab"\\n"ba"', + }, + 855: { + funName: "ExamRoom", + paramTypes: ["number"], + returnType: "void", + testCase: '["ExamRoom","seat","seat","seat","seat","leave","seat"]\\n[[10],[],[],[],[],[4],[]]', + }, + 856: { + funName: "scoreOfParentheses", + paramTypes: ["string"], + returnType: "number", + testCase: '"()"', + }, + 857: { + funName: "mincostToHireWorkers", + paramTypes: ["number[]", "number[]", "number"], + returnType: "number", + testCase: "[10,20,5]\\n[70,50,30]\\n2", + }, + 858: { + funName: "mirrorReflection", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "2\\n1", + }, + 859: { + funName: "buddyStrings", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"ab"\\n"ba"', + }, + 860: { + funName: "lemonadeChange", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[5,5,5,10,20]", + }, + 861: { + funName: "matrixScore", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,0,1,1],[1,0,1,0],[1,1,0,0]]", + }, + 862: { + funName: "shortestSubarray", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1]\\n1", + }, + 863: { + funName: "distanceK", + paramTypes: ["TreeNode", "TreeNode", "number"], + returnType: "number[]", + testCase: "[3,5,1,6,2,0,8,null,null,7,4]\\n5\\n2", + }, + 864: { + funName: "shortestPathAllKeys", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["@.a.#","###.#","b.A.B"]', + }, + 865: { + funName: "subtreeWithAllDeepest", + paramTypes: ["TreeNode"], + returnType: "TreeNode", + testCase: "[3,5,1,6,2,0,8,null,null,7,4]", + }, + 866: { + funName: "primePalindrome", + paramTypes: ["number"], + returnType: "number", + testCase: "6", + }, + 867: { + funName: "transpose", + paramTypes: ["number[][]"], + returnType: "number[][]", + testCase: "[[1,2,3],[4,5,6],[7,8,9]]", + }, + 868: { + funName: "binaryGap", + paramTypes: ["number"], + returnType: "number", + testCase: "22", + }, + 869: { + funName: "reorderedPowerOf2", + paramTypes: ["number"], + returnType: "boolean", + testCase: "1", + }, + 870: { + funName: "advantageCount", + paramTypes: ["number[]", "number[]"], + returnType: "number[]", + testCase: "[2,7,11,15]\\n[1,10,4,11]", + }, + 871: { + funName: "minRefuelStops", + paramTypes: ["number", "number", "number[][]"], + returnType: "number", + testCase: "1\\n1\\n[]", + }, + 872: { + funName: "leafSimilar", + paramTypes: ["TreeNode", "TreeNode"], + returnType: "boolean", + testCase: "[3,5,1,6,2,9,8,null,null,7,4]\\n[3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]", + }, + 873: { + funName: "lenLongestFibSubseq", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3,4,5,6,7,8]", + }, + 874: { + funName: "robotSim", + paramTypes: ["number[]", "number[][]"], + returnType: "number", + testCase: "[4,-1,3]\\n[]", + }, + 875: { + funName: "minEatingSpeed", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[3,6,7,11]\\n8", + }, + 876: { + funName: "middleNode", + paramTypes: ["ListNode"], + returnType: "ListNode", + testCase: "[1,2,3,4,5]", + }, + 877: { + funName: "stoneGame", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[5,3,4,5]", + }, + 878: { + funName: "nthMagicalNumber", + paramTypes: ["number", "number", "number"], + returnType: "number", + testCase: "1\\n2\\n3", + }, + 879: { + funName: "profitableSchemes", + paramTypes: ["number", "number", "number[]", "number[]"], + returnType: "number", + testCase: "5\\n3\\n[2,2]\\n[2,3]", + }, + 880: { + funName: "decodeAtIndex", + paramTypes: ["string", "number"], + returnType: "string", + testCase: '"leet2code3"\\n10', + }, + 881: { + funName: "numRescueBoats", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,2]\\n3", + }, + 882: { + funName: "reachableNodes", + paramTypes: ["number[][]", "number", "number"], + returnType: "number", + testCase: "[[0,1,10],[0,2,1],[1,2,2]]\\n6\\n3", + }, + 883: { + funName: "projectionArea", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[2]]", + }, + 884: { + funName: "uncommonFromSentences", + paramTypes: ["string", "string"], + returnType: "string[]", + testCase: '"this apple is sweet"\\n"this apple is sour"', + }, + 885: { + funName: "spiralMatrixIII", + paramTypes: ["number", "number", "number", "number"], + returnType: "number[][]", + testCase: "1\\n4\\n0\\n0", + }, + 886: { + funName: "possibleBipartition", + paramTypes: ["number", "number[][]"], + returnType: "boolean", + testCase: "4\\n[[1,2],[1,3],[2,4]]", + }, + 887: { + funName: "superEggDrop", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "1\\n2", + }, + 888: { + funName: "fairCandySwap", + paramTypes: ["number[]", "number[]"], + returnType: "number[]", + testCase: "[1,1]\\n[2,2]", + }, + 889: { + funName: "constructFromPrePost", + paramTypes: ["number[]", "number[]"], + returnType: "TreeNode", + testCase: "[1,2,4,5,3,6,7]\\n[4,5,2,6,7,3,1]", + }, + 890: { + funName: "findAndReplacePattern", + paramTypes: ["string[]", "string"], + returnType: "string[]", + testCase: '["abc","deq","mee","aqq","dkd","ccc"]\\n"abb"', + }, + 891: { + funName: "sumSubseqWidths", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,1,3]", + }, + 892: { + funName: "surfaceArea", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[2]]", + }, + 893: { + funName: "numSpecialEquivGroups", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["abcd","cdab","cbad","xyzz","zzxy","zzyx"]', + }, + 894: { + funName: "allPossibleFBT", + paramTypes: ["number"], + returnType: "TreeNode[]", + testCase: "7", + }, + 895: { + funName: "FreqStack", + paramTypes: [], + returnType: "void", + testCase: + '["FreqStack","push","push","push","push","push","push","pop","pop","pop","pop"]\\n[[],[5],[7],[5],[7],[4],[5],[],[],[],[]]', + }, + 896: { + funName: "isMonotonic", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,2,2,3]", + }, + 897: { + funName: "increasingBST", + paramTypes: ["TreeNode"], + returnType: "TreeNode", + testCase: "[5,3,6,2,4,null,8,1,null,null,null,7,9]", + }, + 898: { + funName: "subarrayBitwiseORs", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[0]", + }, + 899: { + funName: "orderlyQueue", + paramTypes: ["string", "number"], + returnType: "string", + testCase: '"cba"\\n1', + }, + 900: { + funName: "RLEIterator", + paramTypes: ["number[]"], + returnType: "void", + testCase: '["RLEIterator","next","next","next","next"]\\n[[[3,8,0,9,2,5]],[2],[1],[1],[2]]', + }, + 901: { + funName: "StockSpanner", + paramTypes: [], + returnType: "void", + testCase: + '["StockSpanner","next","next","next","next","next","next","next"]\\n[[],[100],[80],[60],[70],[60],[75],[85]]', + }, + 902: { + funName: "atMostNGivenDigitSet", + paramTypes: ["string[]", "number"], + returnType: "number", + testCase: '["1","3","5","7"]\\n100', + }, + 903: { + funName: "numPermsDISequence", + paramTypes: ["string"], + returnType: "number", + testCase: '"DID"', + }, + 904: { + funName: "totalFruit", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,1]", + }, + 905: { + funName: "sortArrayByParity", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[3,1,2,4]", + }, + 906: { + funName: "superpalindromesInRange", + paramTypes: ["string", "string"], + returnType: "number", + testCase: '"4"\\n"1000"', + }, + 907: { + funName: "sumSubarrayMins", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,1,2,4]", + }, + 908: { + funName: "smallestRangeI", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1]\\n0", + }, + 909: { + funName: "snakesAndLadders", + paramTypes: ["number[][]"], + returnType: "number", + testCase: + "[[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,35,-1,-1,13,-1],[-1,-1,-1,-1,-1,-1],[-1,15,-1,-1,-1,-1]]", + }, + 910: { + funName: "smallestRangeII", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1]\\n0", + }, + 911: { + funName: "TopVotedCandidate", + paramTypes: ["number[]", "number[]"], + returnType: "void", + testCase: + '["TopVotedCandidate","q","q","q","q","q","q"]\\n[[[0,1,1,0,0,1,0],[0,5,10,15,20,25,30]],[3],[12],[25],[15],[24],[8]]', + }, + 912: { + funName: "sortArray", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[5,2,3,1]", + }, + 913: { + funName: "catMouseGame", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]]", + }, + 914: { + funName: "hasGroupsSizeX", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[1,2,3,4,4,3,2,1]", + }, + 915: { + funName: "partitionDisjoint", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[5,0,3,8,6]", + }, + 916: { + funName: "wordSubsets", + paramTypes: ["string[]", "string[]"], + returnType: "string[]", + testCase: '["amazon","apple","facebook","google","leetcode"]\\n["e","o"]', + }, + 917: { + funName: "reverseOnlyLetters", + paramTypes: ["string"], + returnType: "string", + testCase: '"ab-cd"', + }, + 918: { + funName: "maxSubarraySumCircular", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,-2,3,-2]", + }, + 919: { + funName: "CBTInserter", + paramTypes: ["TreeNode"], + returnType: "void", + testCase: '["CBTInserter","insert","get_root"]\\n[[[1]],[2],[]]', + }, + 920: { + funName: "numMusicPlaylists", + paramTypes: ["number", "number", "number"], + returnType: "number", + testCase: "3\\n3\\n1", + }, + 921: { + funName: "minAddToMakeValid", + paramTypes: ["string"], + returnType: "number", + testCase: '"())"', + }, + 922: { + funName: "sortArrayByParityII", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[4,2,5,7]", + }, + 923: { + funName: "threeSumMulti", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,1,2,2,3,3,4,4,5,5]\\n8", + }, + 924: { + funName: "minMalwareSpread", + paramTypes: ["number[][]", "number[]"], + returnType: "number", + testCase: "[[1,1,0],[1,1,0],[0,0,1]]\\n[0,1]", + }, + 925: { + funName: "isLongPressedName", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"alex"\\n"aaleex"', + }, + 926: { + funName: "minFlipsMonoIncr", + paramTypes: ["string"], + returnType: "number", + testCase: '"00110"', + }, + 927: { + funName: "threeEqualParts", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[1,0,1,0,1]", + }, + 928: { + funName: "minMalwareSpread", + paramTypes: ["number[][]", "number[]"], + returnType: "number", + testCase: "[[1,1,0],[1,1,0],[0,0,1]]\\n[0,1]", + }, + 929: { + funName: "numUniqueEmails", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]', + }, + 930: { + funName: "numSubarraysWithSum", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,0,1,0,1]\\n2", + }, + 931: { + funName: "minFallingPathSum", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,2,3],[4,5,6],[7,8,9]]", + }, + 932: { + funName: "beautifulArray", + paramTypes: ["number"], + returnType: "number[]", + testCase: "4", + }, + 933: { + funName: "RecentCounter", + paramTypes: [], + returnType: "void", + testCase: '["RecentCounter","ping","ping","ping","ping"]\\n[[],[1],[100],[3001],[3002]]', + }, + 934: { + funName: "shortestBridge", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,1],[1,0]]", + }, + 935: { + funName: "knightDialer", + paramTypes: ["number"], + returnType: "number", + testCase: "1", + }, + 936: { + funName: "movesToStamp", + paramTypes: ["string", "string"], + returnType: "number[]", + testCase: '"abc"\\n"ababc"', + }, + 937: { + funName: "reorderLogFiles", + paramTypes: ["string[]"], + returnType: "string[]", + testCase: '["dig1 8 1 5 1","let1 art can","dig2 3 6","let2 own kit dig","let3 art zero"]', + }, + 938: { + funName: "rangeSumBST", + paramTypes: ["TreeNode", "number", "number"], + returnType: "number", + testCase: "[10,5,15,3,7,null,18]\\n7\\n15", + }, + 939: { + funName: "minAreaRect", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,1],[1,3],[3,1],[3,3],[2,2]]", + }, + 940: { + funName: "distinctSubseqII", + paramTypes: ["string"], + returnType: "number", + testCase: '"abc"', + }, + 941: { + funName: "validMountainArray", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[2,1]", + }, + 942: { + funName: "diStringMatch", + paramTypes: ["string"], + returnType: "number[]", + testCase: '"IDID"', + }, + 943: { + funName: "shortestSuperstring", + paramTypes: ["string[]"], + returnType: "string", + testCase: '["alex","loves","leetcode"]', + }, + 944: { + funName: "minDeletionSize", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["cba","daf","ghi"]', + }, + 945: { + funName: "minIncrementForUnique", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,2]", + }, + 946: { + funName: "validateStackSequences", + paramTypes: ["number[]", "number[]"], + returnType: "boolean", + testCase: "[1,2,3,4,5]\\n[4,5,3,2,1]", + }, + 947: { + funName: "removeStones", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]", + }, + 948: { + funName: "bagOfTokensScore", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[100]\\n50", + }, + 949: { + funName: "largestTimeFromDigits", + paramTypes: ["number[]"], + returnType: "string", + testCase: "[1,2,3,4]", + }, + 950: { + funName: "deckRevealedIncreasing", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[17,13,11,2,3,5,7]", + }, + 951: { + funName: "flipEquiv", + paramTypes: ["TreeNode", "TreeNode"], + returnType: "boolean", + testCase: "[1,2,3,4,5,6,null,null,null,7,8]\\n[1,3,2,null,6,4,5,null,null,null,null,8,7]", + }, + 952: { + funName: "largestComponentSize", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[4,6,15,35]", + }, + 953: { + funName: "isAlienSorted", + paramTypes: ["string[]", "string"], + returnType: "boolean", + testCase: '["hello","leetcode"]\\n"hlabcdefgijkmnopqrstuvwxyz"', + }, + 954: { + funName: "canReorderDoubled", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[3,1,3,6]", + }, + 955: { + funName: "minDeletionSize", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["ca","bb","ac"]', + }, + 956: { + funName: "tallestBillboard", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3,6]", + }, + 957: { + funName: "prisonAfterNDays", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[0,1,0,1,1,0,0,1]\\n7", + }, + 958: { + funName: "isCompleteTree", + paramTypes: ["TreeNode"], + returnType: "boolean", + testCase: "[1,2,3,4,5,6]", + }, + 959: { + funName: "regionsBySlashes", + paramTypes: ["string[]"], + returnType: "number", + testCase: '[" /","/ "]', + }, + 960: { + funName: "minDeletionSize", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["babca","bbazb"]', + }, + 961: { + funName: "repeatedNTimes", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3,3]", + }, + 962: { + funName: "maxWidthRamp", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[6,0,8,2,1,5]", + }, + 963: { + funName: "minAreaFreeRect", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,2],[2,1],[1,0],[0,1]]", + }, + 964: { + funName: "leastOpsExpressTarget", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "3\\n19", + }, + 965: { + funName: "isUnivalTree", + paramTypes: ["TreeNode"], + returnType: "boolean", + testCase: "[1,1,1,1,1,null,1]", + }, + 966: { + funName: "spellchecker", + paramTypes: ["string[]", "string[]"], + returnType: "string[]", + testCase: '["KiTe","kite","hare","Hare"]\\n["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"]', + }, + 967: { + funName: "numsSameConsecDiff", + paramTypes: ["number", "number"], + returnType: "number[]", + testCase: "3\\n7", + }, + 968: { + funName: "minCameraCover", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[0,0,null,0,0]", + }, + 969: { + funName: "pancakeSort", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[3,2,4,1]", + }, + 970: { + funName: "powerfulIntegers", + paramTypes: ["number", "number", "number"], + returnType: "number[]", + testCase: "2\\n3\\n10", + }, + 971: { + funName: "flipMatchVoyage", + paramTypes: ["TreeNode", "number[]"], + returnType: "number[]", + testCase: "[1,2]\\n[2,1]", + }, + 972: { + funName: "isRationalEqual", + paramTypes: ["string", "string"], + returnType: "boolean", + testCase: '"0.(52)"\\n"0.5(25)"', + }, + 973: { + funName: "kClosest", + paramTypes: ["number[][]", "number"], + returnType: "number[][]", + testCase: "[[1,3],[-2,2]]\\n1", + }, + 974: { + funName: "subarraysDivByK", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[4,5,0,-2,-3,1]\\n5", + }, + 975: { + funName: "oddEvenJumps", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[10,13,12,14,15]", + }, + 976: { + funName: "largestPerimeter", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,1,2]", + }, + 977: { + funName: "sortedSquares", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[-4,-1,0,3,10]", + }, + 978: { + funName: "maxTurbulenceSize", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[9,4,2,10,7,8,8,1,9]", + }, + 979: { + funName: "distributeCoins", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[3,0,0]", + }, + 980: { + funName: "uniquePathsIII", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[1,0,0,0],[0,0,0,0],[0,0,2,-1]]", + }, + 981: { + funName: "TimeMap", + paramTypes: [], + returnType: "void", + testCase: + '["TimeMap","set","get","get","set","get","get"]\\n[[],["foo","bar",1],["foo",1],["foo",3],["foo","bar2",4],["foo",4],["foo",5]]', + }, + 982: { + funName: "countTriplets", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,1,3]", + }, + 983: { + funName: "mincostTickets", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[1,4,6,7,8,20]\\n[2,7,15]", + }, + 984: { + funName: "strWithout3a3b", + paramTypes: ["number", "number"], + returnType: "string", + testCase: "1\\n2", + }, + 985: { + funName: "sumEvenAfterQueries", + paramTypes: ["number[]", "number[][]"], + returnType: "number[]", + testCase: "[1,2,3,4]\\n[[1,0],[-3,1],[-4,0],[2,3]]", + }, + 986: { + funName: "intervalIntersection", + paramTypes: ["number[][]", "number[][]"], + returnType: "number[][]", + testCase: "[[0,2],[5,10],[13,23],[24,25]]\\n[[1,5],[8,12],[15,24],[25,26]]", + }, + 987: { + funName: "verticalTraversal", + paramTypes: ["TreeNode"], + returnType: "number[][]", + testCase: "[3,9,20,null,null,15,7]", + }, + 988: { + funName: "smallestFromLeaf", + paramTypes: ["TreeNode"], + returnType: "string", + testCase: "[0,1,2,3,4,3,4]", + }, + 989: { + funName: "addToArrayForm", + paramTypes: ["number[]", "number"], + returnType: "number[]", + testCase: "[1,2,0,0]\\n34", + }, + 990: { + funName: "equationsPossible", + paramTypes: ["string[]"], + returnType: "boolean", + testCase: '["a==b","b!=a"]', + }, + 991: { + funName: "brokenCalc", + paramTypes: ["number", "number"], + returnType: "number", + testCase: "2\\n3", + }, + 992: { + funName: "subarraysWithKDistinct", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,2,1,2,3]\\n2", + }, + 993: { + funName: "isCousins", + paramTypes: ["TreeNode", "number", "number"], + returnType: "boolean", + testCase: "[1,2,3,4]\\n4\\n3", + }, + 994: { + funName: "orangesRotting", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[2,1,1],[1,1,0],[0,1,1]]", + }, + 995: { + funName: "minKBitFlips", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[0,1,0]\\n1", + }, + 996: { + funName: "numSquarefulPerms", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,17,8]", + }, + 997: { + funName: "findJudge", + paramTypes: ["number", "number[][]"], + returnType: "number", + testCase: "2\\n[[1,2]]", + }, + 998: { + funName: "insertIntoMaxTree", + paramTypes: ["TreeNode", "number"], + returnType: "TreeNode", + testCase: "[4,1,3,null,null,2]\\n5", + }, + 999: { + funName: "numRookCaptures", + paramTypes: ["character[][]"], + returnType: "number", + testCase: + '[[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]', + }, + 1000: { + funName: "mergeStones", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[3,2,4,1]\\n2", + }, + 1001: { + funName: "gridIllumination", + paramTypes: ["number", "number[][]", "number[][]"], + returnType: "number[]", + testCase: "5\\n[[0,0],[4,4]]\\n[[1,1],[1,0]]", + }, + 1002: { + funName: "commonChars", + paramTypes: ["string[]"], + returnType: "string[]", + testCase: '["bella","label","roller"]', + }, + 1003: { + funName: "isValid", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"aabcbc"', + }, + 1004: { + funName: "longestOnes", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,1,1,0,0,0,1,1,1,1,0]\\n2", + }, + 1005: { + funName: "largestSumAfterKNegations", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[4,2,3]\\n1", + }, + 1006: { + funName: "clumsy", + paramTypes: ["number"], + returnType: "number", + testCase: "4", + }, + 1007: { + funName: "minDominoRotations", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[2,1,2,4,2,2]\\n[5,2,6,2,3,2]", + }, + 1008: { + funName: "bstFromPreorder", + paramTypes: ["number[]"], + returnType: "TreeNode", + testCase: "[8,5,1,7,10,12]", + }, + 1009: { + funName: "bitwiseComplement", + paramTypes: ["number"], + returnType: "number", + testCase: "5", + }, + 1010: { + funName: "numPairsDivisibleBy60", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[30,20,150,100,40]", + }, + 1011: { + funName: "shipWithinDays", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,2,3,4,5,6,7,8,9,10]\\n5", + }, + 1012: { + funName: "numDupDigitsAtMostN", + paramTypes: ["number"], + returnType: "number", + testCase: "20", + }, + 1013: { + funName: "canThreePartsEqualSum", + paramTypes: ["number[]"], + returnType: "boolean", + testCase: "[0,2,1,-6,6,-7,9,1,2,0,1]", + }, + 1014: { + funName: "maxScoreSightseeingPair", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[8,1,5,2,6]", + }, + 1015: { + funName: "smallestRepunitDivByK", + paramTypes: ["number"], + returnType: "number", + testCase: "1", + }, + 1016: { + funName: "queryString", + paramTypes: ["string", "number"], + returnType: "boolean", + testCase: '"0110"\\n3', + }, + 1017: { + funName: "baseNeg2", + paramTypes: ["number"], + returnType: "string", + testCase: "2", + }, + 1018: { + funName: "prefixesDivBy5", + paramTypes: ["number[]"], + returnType: "boolean[]", + testCase: "[0,1,1]", + }, + 1019: { + funName: "nextLargerNodes", + paramTypes: ["ListNode"], + returnType: "number[]", + testCase: "[2,1,5]", + }, + 1020: { + funName: "numEnclaves", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]", + }, + 1021: { + funName: "removeOuterParentheses", + paramTypes: ["string"], + returnType: "string", + testCase: '"(()())(())"', + }, + 1022: { + funName: "sumRootToLeaf", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[1,0,1,0,1,0,1]", + }, + 1023: { + funName: "camelMatch", + paramTypes: ["string[]", "string"], + returnType: "boolean[]", + testCase: '["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"]\\n"FB"', + }, + 1024: { + funName: "videoStitching", + paramTypes: ["number[][]", "number"], + returnType: "number", + testCase: "[[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]]\\n10", + }, + 1025: { + funName: "divisorGame", + paramTypes: ["number"], + returnType: "boolean", + testCase: "2", + }, + 1026: { + funName: "maxAncestorDiff", + paramTypes: ["TreeNode"], + returnType: "number", + testCase: "[8,3,10,1,6,null,14,null,null,4,7,13]", + }, + 1027: { + funName: "longestArithSeqLength", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[3,6,9,12]", + }, + 1028: { + funName: "recoverFromPreorder", + paramTypes: ["string"], + returnType: "TreeNode", + testCase: '"1-2--3--4-5--6--7"', + }, + 1029: { + funName: "twoCitySchedCost", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[10,20],[30,200],[400,50],[30,20]]", + }, + 1030: { + funName: "allCellsDistOrder", + paramTypes: ["number", "number", "number", "number"], + returnType: "number[][]", + testCase: "1\\n2\\n0\\n0", + }, + 1031: { + funName: "maxSumTwoNoOverlap", + paramTypes: ["number[]", "number", "number"], + returnType: "number", + testCase: "[0,6,5,2,2,5,1,9,4]\\n1\\n2", + }, + 1032: { + funName: "StreamChecker", + paramTypes: ["string[]"], + returnType: "void", + testCase: + '["StreamChecker","query","query","query","query","query","query","query","query","query","query","query","query"]\\n[[["cd","f","kl"]],["a"],["b"],["c"],["d"],["e"],["f"],["g"],["h"],["i"],["j"],["k"],["l"]]', + }, + 1033: { + funName: "numMovesStones", + paramTypes: ["number", "number", "number"], + returnType: "number[]", + testCase: "1\\n2\\n5", + }, + 1034: { + funName: "colorBorder", + paramTypes: ["number[][]", "number", "number", "number"], + returnType: "number[][]", + testCase: "[[1,1],[1,2]]\\n0\\n0\\n3", + }, + 1035: { + funName: "maxUncrossedLines", + paramTypes: ["number[]", "number[]"], + returnType: "number", + testCase: "[1,4,2]\\n[1,2,4]", + }, + 1036: { + funName: "isEscapePossible", + paramTypes: ["number[][]", "number[]", "number[]"], + returnType: "boolean", + testCase: "[[0,1],[1,0]]\\n[0,0]\\n[0,2]", + }, + 1037: { + funName: "isBoomerang", + paramTypes: ["number[][]"], + returnType: "boolean", + testCase: "[[1,1],[2,3],[3,2]]", + }, + 1038: { + funName: "bstToGst", + paramTypes: ["TreeNode"], + returnType: "TreeNode", + testCase: "[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]", + }, + 1039: { + funName: "minScoreTriangulation", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,2,3]", + }, + 1040: { + funName: "numMovesStonesII", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[7,4,9]", + }, + 1041: { + funName: "isRobotBounded", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"GGLLGG"', + }, + 1042: { + funName: "gardenNoAdj", + paramTypes: ["number", "number[][]"], + returnType: "number[]", + testCase: "3\\n[[1,2],[2,3],[3,1]]", + }, + 1043: { + funName: "maxSumAfterPartitioning", + paramTypes: ["number[]", "number"], + returnType: "number", + testCase: "[1,15,7,9,2,5,10]\\n3", + }, + 1044: { + funName: "longestDupSubstring", + paramTypes: ["string"], + returnType: "string", + testCase: '"banana"', + }, + 1046: { + funName: "lastStoneWeight", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,7,4,1,8,1]", + }, + 1047: { + funName: "removeDuplicates", + paramTypes: ["string"], + returnType: "string", + testCase: '"abbaca"', + }, + 1048: { + funName: "longestStrChain", + paramTypes: ["string[]"], + returnType: "number", + testCase: '["a","b","ba","bca","bda","bdca"]', + }, + 1049: { + funName: "lastStoneWeightII", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[2,7,4,1,8,1]", + }, + 1051: { + funName: "heightChecker", + paramTypes: ["number[]"], + returnType: "number", + testCase: "[1,1,4,2,1,3]", + }, + 1052: { + funName: "maxSatisfied", + paramTypes: ["number[]", "number[]", "number"], + returnType: "number", + testCase: "[1,0,1,2,1,1,7,5]\\n[0,1,0,1,0,1,0,1]\\n3", + }, + 1053: { + funName: "prevPermOpt1", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[3,2,1]", + }, + 1054: { + funName: "rearrangeBarcodes", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: "[1,1,1,2,2,2]", + }, + 1071: { + funName: "gcdOfStrings", + paramTypes: ["string", "string"], + returnType: "string", + testCase: '"ABCABC"\\n"ABC"', + }, + 1072: { + funName: "maxEqualRowsAfterFlips", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,1],[1,1]]", + }, + 1073: { + funName: "addNegabinary", + paramTypes: ["number[]", "number[]"], + returnType: "number[]", + testCase: "[1,1,1,1,1]\\n[1,0,1]", + }, + 1074: { + funName: "numSubmatrixSumTarget", + paramTypes: ["number[][]", "number"], + returnType: "number", + testCase: "[[0,1,0],[1,1,1],[0,1,0]]\\n0", + }, + 1078: { + funName: "findOcurrences", + paramTypes: ["string", "string", "string"], + returnType: "string[]", + testCase: '"alice is a good girl she is a good student"\\n"a"\\n"good"', + }, + 1079: { + funName: "numTilePossibilities", + paramTypes: ["string"], + returnType: "number", + testCase: '"AAB"', + }, + 1080: { + funName: "sufficientSubset", + paramTypes: ["TreeNode", "number"], + returnType: "TreeNode", + testCase: "[1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14]\\n1", + }, + 1081: { + funName: "smallestSubsequence", + paramTypes: ["string"], + returnType: "string", + testCase: '"cdadabcc"', + }, + 1089: { + funName: "duplicateZeros", + paramTypes: ["number[]"], + returnType: "void", + testCase: "[1,0,2,3,0,4,5,0]", + }, + 1090: { + funName: "largestValsFromLabels", + paramTypes: ["number[]", "number[]", "number", "number"], + returnType: "number", + testCase: "[5,4,3,2,1]\\n[1,1,2,2,3]\\n3\\n1", + }, + 1091: { + funName: "shortestPathBinaryMatrix", + paramTypes: ["number[][]"], + returnType: "number", + testCase: "[[0,1],[1,0]]", + }, + 1092: { + funName: "shortestCommonSupersequence", + paramTypes: ["string", "string"], + returnType: "string", + testCase: '"abac"\\n"cab"', + }, + 1093: { + funName: "sampleStats", + paramTypes: ["number[]"], + returnType: "number[]", + testCase: + "[0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]", + }, + 1094: { + funName: "carPooling", + paramTypes: ["number[][]", "number"], + returnType: "boolean", + testCase: "[[2,1,5],[3,3,7]]\\n4", + }, + 1095: { + funName: "findInMountainArray", + // change the order of paramTypes + paramTypes: ["MountainArray", "number"], + returnType: "number", + testCase: "[1,2,3,4,5,3,1]\\n3", + }, + 1096: { + funName: "braceExpansionII", + paramTypes: ["string"], + returnType: "string[]", + testCase: '"{a,b}{c,{d,e}}"', + }, + 1103: { + funName: "distributeCandies", + paramTypes: ["number", "number"], + returnType: "number[]", + testCase: "7\\n4", + }, + 1104: { + funName: "pathInZigZagTree", + paramTypes: ["number"], + returnType: "number[]", + testCase: "14", + }, + 1105: { + funName: "minHeightShelves", + paramTypes: ["number[][]", "number"], + returnType: "number", + testCase: "[[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]]\\n4", + }, + 1106: { + funName: "parseBoolExpr", + paramTypes: ["string"], + returnType: "boolean", + testCase: '"!(f)"', + }, +}; diff --git a/src/utils/problemUtils.ts b/src/utils/problemUtils.ts new file mode 100644 index 0000000..96448b5 --- /dev/null +++ b/src/utils/problemUtils.ts @@ -0,0 +1,201 @@ +import * as fse from "fs-extra"; +import * as path from "path"; +import * as vscode from "vscode"; +import problemTypes from "./problemTypes"; + +import { useWsl, isWindows, usingCmd } from "./SystemUtils"; + +const fileMateReg: RegExp = /@lc\s+(?:[\s\S]*?)\s+id=(\d+)\s+lang=([\S]+)/; + +const beforeStubReg: RegExp = /@before-stub-for-debug-begin([\s\S]*?)@before-stub-for-debug-end/; +const afterStubReg: RegExp = /@after-stub-for-debug-begin([\s\S]*?)@after-stub-for-debug-end/; + +interface IExtensionState { + context: vscode.ExtensionContext; + cachePath: string; +} + +export interface IDebugConfig { + type: string; + program?: string; + env?: { + [key: string]: any; + }; + [x: string]: any; +} + +export interface IProblemType { + funName: string; + paramTypes: string[]; + returnType: string; + testCase: string; + specialFunName?: { + [x: string]: string; + }; +} + +export interface IDebugResult { + type: "success" | "error"; + message: string; + problemNum: number; + language: string; + filePath: string; + testString: string; +} + +export const extensionState: IExtensionState = { + context: null as any, + cachePath: "", +}; + +export const languages: string[] = [ + "bash", + "c", + "cpp", + "csharp", + "golang", + "java", + "javascript", + "kotlin", + "mysql", + "php", + "python", + "python3", + "ruby", + "rust", + "scala", + "swift", +]; + +export const langExt: Map = new Map([ + ["bash", "sh"], + ["c", "c"], + ["cpp", "cpp"], + ["csharp", "cs"], + ["golang", "go"], + ["java", "java"], + ["javascript", "js"], + ["kotlin", "kt"], + ["mysql", "sql"], + ["php", "php"], + ["python", "py"], + ["python3", "py"], + ["ruby", "rb"], + ["rust", "rs"], + ["scala", "scala"], + ["swift", "swift"], +]); + +export const supportDebugLanguages: string[] = ["javascript", "python3", "cpp"]; + +export interface ProblemMeta { + id: string; + lang: string; +} + +export function genFileExt(language: string): string { + const ext: string | undefined = langExt.get(language); + if (!ext) { + throw new Error(`The language "${language}" is not supported.`); + } + return ext; +} + +export function canDebug(meta: ProblemMeta | null) { + if (meta == null || supportDebugLanguages.indexOf(meta.lang) === -1 || problemTypes[meta.id] == null) { + return false; + } + return true; +} + +export function fileMeta(content: string): ProblemMeta | null { + const result: RegExpExecArray | null = fileMateReg.exec(content); + if (result != null) { + return { + id: result[1], + lang: result[2], + }; + } + return null; +} + +export async function getUnstubedFile(filePath: string): Promise { + const content: string = (await fse.readFile(filePath)).toString(); + const stripped: string = content.replace(beforeStubReg, "").replace(afterStubReg, ""); + + if (content.length === stripped.length) { + // no stub, return original filePath + return filePath; + } + + const meta: { id: string; lang: string } | null = fileMeta(content); + if (meta == null) { + vscode.window.showErrorMessage( + "File meta info has been changed, please check the content: '@lc app=leetcode.cn id=xx lang=xx'." + ); + throw new Error(""); + } + + const newPath: string = path.join(extensionState.cachePath, `${meta.id}-${meta.lang}`); + await fse.writeFile(newPath, stripped); + return newPath; +} + +export async function getProblemSpecialCode( + language: string, + problem: string, + fileExt: string, + extDir: string +): Promise { + const problemPath: string = path.join(extDir, "src/debug/entry", language, "problems", `${problem}.${fileExt}`); + const isSpecial: boolean = await fse.pathExists(problemPath); + if (isSpecial) { + const specialContent: Buffer = await fse.readFile(problemPath); + return specialContent.toString(); + } + if (language === "cpp") { + return ""; + } + const fileContent: Buffer = await fse.readFile( + path.join(extDir, "src/debug/entry", language, "problems", `common.${fileExt}`) + ); + return fileContent.toString(); +} + +export async function getEntryFile(language: string, problem: string): Promise { + const extDir: string = vscode.extensions.getExtension("ccagml.vscode-leetcode-problem-rating")!.extensionPath; + const fileExt: string = genFileExt(language); + const specialCode: string = await getProblemSpecialCode(language, problem, fileExt, extDir); + const tmpEntryCode: string = ( + await fse.readFile(path.join(extDir, "src/debug/entry", language, `entry.${fileExt}`)) + ).toString(); + const entryCode: string = tmpEntryCode.replace(/\/\/ @@stub-for-code@@/, specialCode); + const entryPath: string = path.join(extensionState.cachePath, `${language}problem${problem}.${fileExt}`); + await fse.writeFile(entryPath, entryCode); + return entryPath; +} + +export function parseTestString(test: string): string { + if (useWsl() || !isWindows()) { + return `'${test}'`; + } + + // In windows and not using WSL + if (usingCmd()) { + return `"${test.replace(/"/g, '\\"')}"`; + } else { + // Assume using PowerShell + return `'${test.replace(/"/g, '\\"')}'`; + } +} + +export function randomString(len: number): string { + len = len || 32; + const $chars: string = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; + const maxPos: number = $chars.length; + let pwd: string = ""; + for (let i: number = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +} From ab8d2210cc456375a8782905f9dcbda1b30be471 Mon Sep 17 00:00:00 2001 From: ccagml Date: Mon, 6 Feb 2023 11:02:28 +0800 Subject: [PATCH 10/11] update --- CHANGELOG.md | 4 + README.md | 45 +++-- package.json | 2 +- {src => resources}/debug/entry/cpp/entry.cpp | 0 .../debug/entry/cpp/problems/116.cpp | 0 .../debug/entry/cpp/problems/116.h | 0 .../debug/entry/cpp/problems/133.cpp | 0 .../debug/entry/cpp/problems/133.h | 0 .../debug/entry/cpp/problems/138.cpp | 0 .../debug/entry/cpp/problems/138.h | 0 .../debug/entry/cpp/problems/278.cpp | 0 .../debug/entry/cpp/problems/278.h | 0 .../debug/entry/cpp/problems/429.cpp | 0 .../debug/entry/cpp/problems/429.h | 0 .../debug/entry/cpp/problems/843.cpp | 0 .../debug/entry/cpp/problems/843.h | 0 .../debug/entry/cpp/problems/common.cpp | 0 .../debug/entry/cpp/problems/common.h | 0 .../debug/entry/javascript/entry.js | 3 +- .../debug/entry/javascript/problems/1095.js | 0 .../debug/entry/javascript/problems/116.js | 0 .../debug/entry/javascript/problems/117.js | 0 .../debug/entry/javascript/problems/133.js | 0 .../debug/entry/javascript/problems/138.js | 0 .../debug/entry/javascript/problems/278.js | 0 .../debug/entry/javascript/problems/341.js | 0 .../debug/entry/javascript/problems/429.js | 0 .../debug/entry/javascript/problems/559.js | 0 .../debug/entry/javascript/problems/589.js | 0 .../debug/entry/javascript/problems/590.js | 0 .../debug/entry/javascript/problems/843.js | 0 .../debug/entry/javascript/problems/common.js | 0 .../debug/entry/python3/entry.py | 1 + .../debug/entry/python3/problems/1095.py | 0 .../debug/entry/python3/problems/116.py | 0 .../debug/entry/python3/problems/117.py | 0 .../debug/entry/python3/problems/133.py | 0 .../debug/entry/python3/problems/138.py | 0 .../debug/entry/python3/problems/278.py | 0 .../debug/entry/python3/problems/429.py | 0 .../debug/entry/python3/problems/559.py | 0 .../debug/entry/python3/problems/589.py | 0 .../debug/entry/python3/problems/590.py | 0 .../debug/entry/python3/problems/843.py | 0 .../debug/entry/python3/problems/common.py | 0 {src => resources}/debug/thirdparty/c/cJSON.c | 0 {src => resources}/debug/thirdparty/c/cJSON.h | 0 src/controller/DebugController.ts | 16 +- src/debug/debugExecutor.ts | 187 ------------------ src/debugex/debugBase.ts | 15 ++ .../cppExecutor.ts => debugex/debugCpp.ts} | 45 +++-- src/debugex/debugJs.ts | 0 src/debugex/debugPy3.ts | 0 src/extension.ts | 2 +- src/service/DebugService.ts | 14 +- src/service/FileButtonService.ts | 39 ++-- src/utils/problemUtils.ts | 10 +- tsconfig.json | 2 +- 58 files changed, 118 insertions(+), 267 deletions(-) rename {src => resources}/debug/entry/cpp/entry.cpp (100%) rename {src => resources}/debug/entry/cpp/problems/116.cpp (100%) rename {src => resources}/debug/entry/cpp/problems/116.h (100%) rename {src => resources}/debug/entry/cpp/problems/133.cpp (100%) rename {src => resources}/debug/entry/cpp/problems/133.h (100%) rename {src => resources}/debug/entry/cpp/problems/138.cpp (100%) rename {src => resources}/debug/entry/cpp/problems/138.h (100%) rename {src => resources}/debug/entry/cpp/problems/278.cpp (100%) rename {src => resources}/debug/entry/cpp/problems/278.h (100%) rename {src => resources}/debug/entry/cpp/problems/429.cpp (100%) rename {src => resources}/debug/entry/cpp/problems/429.h (100%) rename {src => resources}/debug/entry/cpp/problems/843.cpp (100%) rename {src => resources}/debug/entry/cpp/problems/843.h (100%) rename {src => resources}/debug/entry/cpp/problems/common.cpp (100%) rename {src => resources}/debug/entry/cpp/problems/common.h (100%) rename {src => resources}/debug/entry/javascript/entry.js (98%) rename {src => resources}/debug/entry/javascript/problems/1095.js (100%) rename {src => resources}/debug/entry/javascript/problems/116.js (100%) rename {src => resources}/debug/entry/javascript/problems/117.js (100%) rename {src => resources}/debug/entry/javascript/problems/133.js (100%) rename {src => resources}/debug/entry/javascript/problems/138.js (100%) rename {src => resources}/debug/entry/javascript/problems/278.js (100%) rename {src => resources}/debug/entry/javascript/problems/341.js (100%) rename {src => resources}/debug/entry/javascript/problems/429.js (100%) rename {src => resources}/debug/entry/javascript/problems/559.js (100%) rename {src => resources}/debug/entry/javascript/problems/589.js (100%) rename {src => resources}/debug/entry/javascript/problems/590.js (100%) rename {src => resources}/debug/entry/javascript/problems/843.js (100%) rename {src => resources}/debug/entry/javascript/problems/common.js (100%) rename {src => resources}/debug/entry/python3/entry.py (95%) rename {src => resources}/debug/entry/python3/problems/1095.py (100%) rename {src => resources}/debug/entry/python3/problems/116.py (100%) rename {src => resources}/debug/entry/python3/problems/117.py (100%) rename {src => resources}/debug/entry/python3/problems/133.py (100%) rename {src => resources}/debug/entry/python3/problems/138.py (100%) rename {src => resources}/debug/entry/python3/problems/278.py (100%) rename {src => resources}/debug/entry/python3/problems/429.py (100%) rename {src => resources}/debug/entry/python3/problems/559.py (100%) rename {src => resources}/debug/entry/python3/problems/589.py (100%) rename {src => resources}/debug/entry/python3/problems/590.py (100%) rename {src => resources}/debug/entry/python3/problems/843.py (100%) rename {src => resources}/debug/entry/python3/problems/common.py (100%) rename {src => resources}/debug/thirdparty/c/cJSON.c (100%) rename {src => resources}/debug/thirdparty/c/cJSON.h (100%) delete mode 100644 src/debug/debugExecutor.ts create mode 100644 src/debugex/debugBase.ts rename src/{debug/executor/cppExecutor.ts => debugex/debugCpp.ts} (92%) create mode 100644 src/debugex/debugJs.ts create mode 100644 src/debugex/debugPy3.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 65bd873..6d65b3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## version 2.15.1 + +- 参考 wangtao0101/vscode-debug-leetcode 添加 debug + ## version 2.14.2 - BWC96 & WC328 & WC329 数据 diff --git a/README.md b/README.md index e0705ac..5ddc606 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ - [新增题目自定义分类](#新增在工作目录存放数据) - [答案不同上色,配置默认不开启](#插件配置项) - 增加获取中文站的题解 +- 增加 cpp、js、py3 一些题目的 debug(参考其他项目,有问题提 issues) # 关于本项目 @@ -152,27 +153,27 @@ ## 插件配置项 -| 配置项名称显示红色为与官方配置有不同的地方 | 描述 | 默认值 | -| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | -| leetcode-problem-rating.hideSolved | 指定是否要隐藏已解决的问题 | `false` | -| leetcode-problem-rating.showLocked` | 指定是否显示付费题目,只有付费账户才可以打开付费题目 | `false` | -| leetcode-problem-rating.defaultLanguage | 指定答题时使用的默认语言,可选语言有:`bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`, `rust`, `scala`, `swift`, `typescript` | `N/A` | -| leetcode-problem-rating.useWsl | 指定是否启用 WSL | `false` | -| leetcode-problem-rating.endpoint | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | leetcode.cn | -| leetcode-problem-rating.workspaceFolder | 指定保存文件的工作区目录 | `""` | -| leetcode-problem-rating.filePath | 指定生成题目文件的相对文件夹路径名和文件名。点击查看[更多详细用法](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E9%A2%98%E7%9B%AE%E6%96%87%E4%BB%B6%E7%9A%84%E7%9B%B8%E5%AF%B9%E6%96%87%E4%BB%B6%E5%A4%B9%E8%B7%AF%E5%BE%84%E5%92%8C%E6%96%87%E4%BB%B6%E5%90%8D)。 额外拓展\${yyyymmdd}、${timestamp}格式| | -| leetcode-problem-rating.enableStatusBar | 指定是否在 VS Code 下方显示插件状态栏。 增加周赛分数据 | `true` | -| leetcode-problem-rating.editor.shortcuts | 指定在编辑器内所自定义的快捷方式。可用的快捷方式有: `submit`, `test`, `star`, `solution`, `description`, case, allcase 。 | ["submit, case, allcase, test, solution"] | -| leetcode-problem-rating.enableSideMode | 指定在解决一道题时,是否将`问题预览`、`高票答案`与`提交结果`窗口集中在编辑器的第二栏。 | `true` | -| leetcode-problem-rating.nodePath | 指定 `Node.js` 可执行文件的路径。如:C:\Program Files\nodejs\node.exe | `node` | -| leetcode-problem-rating.showCommentDescription | 指定是否要在注释中显示题干。 | `false` | -| leetcode-problem-rating.useEndpointTranslation | 是否显示翻译版本内容。 | `true` | -| leetcode-problem-rating.sortStrategy | 排序的选项。Acceptance Rate (Ascending):通过率递增 Acceptance Rate (Descending):通过率递减 Score (Ascending):分数递增 Score (Descending):分数递减 | None | -| leetcode-problem-rating.pickOneByRankRangeMin | 随机一题的最小浮动,随机一题最低分(你的竞赛分+本配置)。 | 50 | -| leetcode-problem-rating.pickOneByRankRangeMax | 随机一题的最大浮动,随机一题最高分(你的竞赛分+本配置)。 | 150 | -| leetcode-problem-rating.hideScore | 隐藏分数相关的题目。Score:隐藏有分数的题目, NoScore:隐藏没有分数的题目, ScoreRange:隐藏分数范围外的题目 | None | -| leetcode-problem-rating.useVscodeNode | 默认情况下使用 VsCode 自带 Node 环境,不需要额外安装 Node 环境 | true | -| leetcode-problem-rating.answerDiffColor | 答案不同的地方上色 | false | +| 配置项名称显示红色为与官方配置有不同的地方 | 描述 | 默认值 | +| --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | +| leetcode-problem-rating.hideSolved | 指定是否要隐藏已解决的问题 | `false` | +| leetcode-problem-rating.showLocked` | 指定是否显示付费题目,只有付费账户才可以打开付费题目 | `false` | +| leetcode-problem-rating.defaultLanguage | 指定答题时使用的默认语言,可选语言有:`bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`, `rust`, `scala`, `swift`, `typescript` | `N/A` | +| leetcode-problem-rating.useWsl | 指定是否启用 WSL | `false` | +| leetcode-problem-rating.endpoint | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | leetcode.cn | +| leetcode-problem-rating.workspaceFolder | 指定保存文件的工作区目录 | `""` | +| leetcode-problem-rating.filePath | 指定生成题目文件的相对文件夹路径名和文件名。点击查看[更多详细用法](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E9%A2%98%E7%9B%AE%E6%96%87%E4%BB%B6%E7%9A%84%E7%9B%B8%E5%AF%B9%E6%96%87%E4%BB%B6%E5%A4%B9%E8%B7%AF%E5%BE%84%E5%92%8C%E6%96%87%E4%BB%B6%E5%90%8D)。 额外拓展\${yyyymmdd}、${timestamp}格式 | | +| leetcode-problem-rating.enableStatusBar | 指定是否在 VS Code 下方显示插件状态栏。 增加周赛分数据 | `true` | +| leetcode-problem-rating.editor.shortcuts | 指定在编辑器内所自定义的快捷方式。可用的快捷方式有: `submit`, `test`, `star`, `solution`, `description`, case, allcase 。 | ["submit, case, allcase, test, solution"] | +| leetcode-problem-rating.enableSideMode | 指定在解决一道题时,是否将`问题预览`、`高票答案`与`提交结果`窗口集中在编辑器的第二栏。 | `true` | +| leetcode-problem-rating.nodePath | 指定 `Node.js` 可执行文件的路径。如:C:\Program Files\nodejs\node.exe | `node` | +| leetcode-problem-rating.showCommentDescription | 指定是否要在注释中显示题干。 | `false` | +| leetcode-problem-rating.useEndpointTranslation | 是否显示翻译版本内容。 | `true` | +| leetcode-problem-rating.sortStrategy | 排序的选项。Acceptance Rate (Ascending):通过率递增 Acceptance Rate (Descending):通过率递减 Score (Ascending):分数递增 Score (Descending):分数递减 | None | +| leetcode-problem-rating.pickOneByRankRangeMin | 随机一题的最小浮动,随机一题最低分(你的竞赛分+本配置)。 | 50 | +| leetcode-problem-rating.pickOneByRankRangeMax | 随机一题的最大浮动,随机一题最高分(你的竞赛分+本配置)。 | 150 | +| leetcode-problem-rating.hideScore | 隐藏分数相关的题目。Score:隐藏有分数的题目, NoScore:隐藏没有分数的题目, ScoreRange:隐藏分数范围外的题目 | None | +| leetcode-problem-rating.useVscodeNode | 默认情况下使用 VsCode 自带 Node 环境,不需要额外安装 Node 环境 | true | +| leetcode-problem-rating.answerDiffColor | 答案不同的地方上色 | false | ## 更新日志 @@ -182,6 +183,8 @@ - 本插件基于[LeetCode-OpenSource](https://github.com/LeetCode-OpenSource)的[vscode-leetcode](https://github.com/LeetCode-OpenSource/vscode-leetcode/) - 题目分数数据基于[zerotrac](https://github.com/zerotrac)的[leetcode_problem_rating](https://github.com/zerotrac/leetcode_problem_rating/)每周的更新 +- 插件 debug 参考[wangtao0101](https://github.com/wangtao0101/vscode-debug-leetcode) +