diff --git a/.gitignore b/.gitignore
index 003c7195..8bc32d6b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -64,3 +64,5 @@ out
# Mac
.DS_Store
+
+__pycache__
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 00000000..e6525f88
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,7 @@
+{
+ "singleQuote": false,
+ "trailingComma": "all",
+ "printWidth": 120,
+ "tabWidth": 4,
+ "jsxBracketSameLine": true
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
index a2d0a8b1..c18bfe76 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -10,5 +10,51 @@
".vscode-test": true
},
"tslint.autoFixOnSave": true,
- "tslint.ignoreDefinitionFiles": true
-}
\ No newline at end of file
+ "tslint.ignoreDefinitionFiles": true,
+ "C_Cpp.errorSquiggles": "Disabled",
+ "files.associations": {
+ ".prettierrc": "yaml",
+ "cjson.c": "cpp",
+ "iostream": "cpp",
+ "ostream": "cpp",
+ "array": "cpp",
+ "string_view": "cpp",
+ "initializer_list": "cpp",
+ "utility": "cpp",
+ "new": "cpp",
+ "vector": "cpp",
+ "atomic": "cpp",
+ "*.tcc": "cpp",
+ "cctype": "cpp",
+ "clocale": "cpp",
+ "cmath": "cpp",
+ "cstdarg": "cpp",
+ "cstddef": "cpp",
+ "cstdint": "cpp",
+ "cstdio": "cpp",
+ "cstdlib": "cpp",
+ "cstring": "cpp",
+ "cwchar": "cpp",
+ "cwctype": "cpp",
+ "deque": "cpp",
+ "unordered_map": "cpp",
+ "exception": "cpp",
+ "algorithm": "cpp",
+ "memory": "cpp",
+ "memory_resource": "cpp",
+ "optional": "cpp",
+ "string": "cpp",
+ "system_error": "cpp",
+ "tuple": "cpp",
+ "type_traits": "cpp",
+ "fstream": "cpp",
+ "iosfwd": "cpp",
+ "istream": "cpp",
+ "limits": "cpp",
+ "sstream": "cpp",
+ "stdexcept": "cpp",
+ "streambuf": "cpp",
+ "typeinfo": "cpp",
+ "queue": "cpp"
+ }
+}
diff --git a/.vscodeignore b/.vscodeignore
index 8cdceec0..a495b7d8 100644
--- a/.vscodeignore
+++ b/.vscodeignore
@@ -3,6 +3,7 @@
out/test/**
test/**
src/**
+!src/debug/entry/**
**/*.map
.gitignore
.travis.yml
@@ -13,3 +14,4 @@ tslint.json
ACKNOWLEDGEMENTS.md
docs
.github
+__pycache__
diff --git a/README.md b/README.md
index fecddd1b..347ee224 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,61 @@
-# LeetCode
+# Debug LeetCode
-> Solve LeetCode problems in VS Code
+> Solve LeetCode problems in VS Code and enjoy debugging
+
+## About Debug LeetCode
+
+> This extension is a fork of extension [vscode-leetcode](https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-leetcode). Currently, the only difference between two extension is debugging.
+
+### Debug a Problem
+
+
+
+> Currently debug-leetcode only support Python3 and Javascript language and in the future we will support more lanuages which support vscode debug protocal. Welcome to get PR for another language. My next plan is to support c and c++.
+
+> Not all problems are supported(most free problems are supported) and only supported problems have debug option.
+
+> If you have any issue about the debug feature, you can [create a issue](https://github.com/wangtao0101/vscode-leetcode/issues/new?template=bug.md) with detail information
+
+- Python3 debug Requirement
+
+ - Step 1. Install a supported version of Python3 on your system (note: that the system install of Python on macOS is not supported).
+
+ - Step 2. Install the Python extension for Visual Studio Code.
+
+- Javasript debug Requirement
+
+ Nothing just vscode
+
+# Be careful ❗️
+
+Extention will generate some stub code in your current file like:
+
+For python:
+
+```python
+# @before-stub-for-debug-begin
+from python3problem1 import *
+from typing import *
+# @before-stub-for-debug-end
+```
+
+For javascript
+
+```js
+// @after-stub-for-debug-begin
+module.exports = twoSum;
+// @after-stub-for-debug-end
+```
+
+If you delete some stub code and forget to restore, you can delete all the stub code and the extension will generate again in next debug.
+
+---
+
+## About why to publish another leetcode extension.
+
+See [issue](https://github.com/jdneo/vscode-leetcode/issues/241) and [PR](https://github.com/jdneo/vscode-leetcode/pull/525)
+
+If you want to use this extension you may need uninstall another otherwise they may conflict.
@@ -20,9 +75,10 @@
-- English Document | [中文文档](https://github.com/jdneo/vscode-leetcode/blob/master/docs/README_zh-CN.md)
+- English Document | [中文文档](https://github.com/wangtao0101/vscode-leetcode/blob/master/docs/README_zh-CN.md)
## ❗️ Attention ❗️- Workaround to login to LeetCode endpoint
+
> Note: If you are using `leetcode-cn.com`, you can just ignore this section.
Recently we observed that [the extension cannot login to leetcode.com endpoint anymore](https://github.com/jdneo/vscode-leetcode/issues/478). The root cause of this issue is that leetcode.com changed its login mechanism and so far there is no ideal way to fix that issue.
@@ -32,8 +88,9 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
> Note: If you want to use third-party login(**Recommended**), please make sure your account has been connected to the thrid-party. If you want to use `Cookie` login, click [here](https://github.com/jdneo/vscode-leetcode/issues/478#issuecomment-564757098) to see the steps.
## Requirements
-- [VS Code 1.30.1+](https://code.visualstudio.com/)
-- [Node.js 8+](https://nodejs.org)
+
+- [VS Code 1.30.1+](https://code.visualstudio.com/)
+- [Node.js 8+](https://nodejs.org)
> NOTE: Please make sure that `Node` is in your `PATH` environment variable. You can also use the setting `leetcode.nodePath` to specify the location of your `Node.js` executable.
## Quick Start
@@ -43,95 +100,104 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
## Features
### Sign In/Out
+
-- Simply click `Sign in to LeetCode` in the `LeetCode Explorer` will let you **sign in** with your LeetCode account.
+- Simply click `Sign in to LeetCode` in the `LeetCode Explorer` will let you **sign in** with your LeetCode account.
+
+- You can also use the following command to sign in/out:
+ - **LeetCode: Sign in**
+ - **LeetCode: Sign out**
-- You can also use the following command to sign in/out:
- - **LeetCode: Sign in**
- - **LeetCode: Sign out**
---
### Switch Endpoint
+
-- By clicking the button  at the **explorer's navigation bar**, you can switch between different endpoints.
+- By clicking the button  at the **explorer's navigation bar**, you can switch between different endpoints.
+
+- The supported endpoints are:
-- The supported endpoints are:
- - **leetcode.com**
- - **leetcode-cn.com**
+ - **leetcode.com**
+ - **leetcode-cn.com**
- > Note: The accounts of different endpoints are **not** shared. Please make sure you are using the right endpoint. The extension will use `leetcode.com` by default.
+ > Note: The accounts of different endpoints are **not** shared. Please make sure you are using the right endpoint. The extension will use `leetcode.com` by default.
---
### Pick a Problem
+
-- Directly click on the problem or right click the problem in the `LeetCode Explorer` and select `Preview Problem` to see the problem description.
-- Select `Show Problem` to directly open the file with the problem description.
+- Directly click on the problem or right click the problem in the `LeetCode Explorer` and select `Preview Problem` to see the problem description.
+- Select `Show Problem` to directly open the file with the problem description.
- > Note:You can specify the path of the workspace folder to store the problem files by updating the setting `leetcode.workspaceFolder`. The default value is:**$HOME/.leetcode/**.
+ > Note:You can specify the path of the workspace folder to store the problem files by updating the setting `leetcode.workspaceFolder`. The default value is:**\$HOME/.leetcode/**.
- > You can specify whether including the problem description in comments or not by updating the setting `leetcode.showCommentDescription`.
+ > You can specify whether including the problem description in comments or not by updating the setting `leetcode.showCommentDescription`.
- > You can switch the default language by triggering the command: `LeetCode: Switch Default Language`.
+ > You can switch the default language by triggering the command: `LeetCode: Switch Default Language`.
---
### Editor Shortcuts
+
-- The extension supports 4 editor shortcuts (aka Code Lens):
- - `Submit`: Submit your answer to LeetCode.
- - `Test`: Test your answer with customized test cases.
- - `Solution`: Show the top voted solution for the current problem.
- - `Description`: Show the problem description page.
+- The extension supports 4 editor shortcuts (aka Code Lens):
+
+ - `Submit`: Submit your answer to LeetCode.
+ - `Test`: Test your answer with customized test cases.
+ - `Solution`: Show the top voted solution for the current problem.
+ - `Description`: Show the problem description page.
- > Note: You can customize the shortcuts using the setting: `leetcode.editor.shortcuts`. By default, only `Submit` and `Test` shortcuts are enabled.
+ > Note: You can customize the shortcuts using the setting: `leetcode.editor.shortcuts`. By default, only `Submit` and `Test` shortcuts are enabled.
---
### Search problems by Keywords
+
-- By clicking the button  at the **explorer's navigation bar**, you can search the problems by keywords.
+- By clicking the button  at the **explorer's navigation bar**, you can search the problems by keywords.
---
### Manage Session
+
-- To manage your LeetCode sessions, just clicking the `LeetCode: ***` at the bottom of the status bar. You can **switch** between sessions or **create**, **delete** a session.
-
+- To manage your LeetCode sessions, just clicking the `LeetCode: ***` at the bottom of the status bar. You can **switch** between sessions or **create**, **delete** a session.
## Settings
-| Setting Name | Description | Default Value |
-| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
-| `leetcode.hideSolved` | Specify to hide the solved problems or not | `false` |
-| `leetcode.showLocked` | Specify to show the locked problems or not. Only Premium users could open the locked problems | `false` |
-| `leetcode.defaultLanguage` | Specify the default language used to solve the problem. Supported languages are: `bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`,`rust`, `scala`,`swift` | `N/A` |
-| `leetcode.useWsl` | Specify whether to use WSL or not | `false` |
-| `leetcode.endpoint` | Specify the active endpoint. Supported endpoints are: `leetcode`, `leetcode-cn` | `leetcode` |
-| `leetcode.workspaceFolder` | Specify the path of the workspace folder to store the problem files. | `""` |
-| `leetcode.filePath` | Specify the relative path under the workspace and the file name to save the problem files. More details can be found [here](https://github.com/jdneo/vscode-leetcode/wiki/Customize-the-Relative-Folder-and-the-File-Name-of-the-Problem-File). | |
-| `leetcode.enableStatusBar` | Specify whether the LeetCode status bar will be shown or not. | `true` |
-| `leetcode.editor.shortcuts` | Specify the customized shorcuts in editors. Supported values are: `submit`, `test`, `solution` and `description`. | `["submit, test"]` |
-| `leetcode.enableSideMode` | Specify whether `preview`, `solution` and `submission` tab should be grouped into the second editor column when solving a problem. | `true` |
-| `leetcode.nodePath` | Specify the `Node.js` executable path. for example, C:\Program Files\nodejs\node.exe | `node` |
-| `leetcode.showCommentDescription` | Specify whether to include the problem description in the comments | `false` |
+
+| Setting Name | Description | Default Value |
+| --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
+| `leetcode.hideSolved` | Specify to hide the solved problems or not | `false` |
+| `leetcode.showLocked` | Specify to show the locked problems or not. Only Premium users could open the locked problems | `false` |
+| `leetcode.defaultLanguage` | Specify the default language used to solve the problem. Supported languages are: `bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`,`rust`, `scala`,`swift` | `N/A` |
+| `leetcode.useWsl` | Specify whether to use WSL or not | `false` |
+| `leetcode.endpoint` | Specify the active endpoint. Supported endpoints are: `leetcode`, `leetcode-cn` | `leetcode` |
+| `leetcode.workspaceFolder` | Specify the path of the workspace folder to store the problem files. | `""` |
+| `leetcode.filePath` | Specify the relative path under the workspace and the file name to save the problem files. More details can be found [here](https://github.com/jdneo/vscode-leetcode/wiki/Customize-the-Relative-Folder-and-the-File-Name-of-the-Problem-File). | |
+| `leetcode.enableStatusBar` | Specify whether the LeetCode status bar will be shown or not. | `true` |
+| `leetcode.editor.shortcuts` | Specify the customized shorcuts in editors. Supported values are: `submit`, `test`, `solution` and `description`. | `["submit, test"]` |
+| `leetcode.enableSideMode` | Specify whether `preview`, `solution` and `submission` tab should be grouped into the second editor column when solving a problem. | `true` |
+| `leetcode.nodePath` | Specify the `Node.js` executable path. for example, C:\Program Files\nodejs\node.exe | `node` |
+| `leetcode.showCommentDescription` | Specify whether to include the problem description in the comments | `false` |
## Want Help?
@@ -145,5 +211,5 @@ Refer to [CHANGELOG](https://github.com/jdneo/vscode-leetcode/blob/master/CHANGE
## Acknowledgement
-- This extension is based on [@skygragon](https://github.com/skygragon)'s [leetcode-cli](https://github.com/skygragon/leetcode-cli) open source project.
-- Special thanks to our [contributors](https://github.com/jdneo/vscode-leetcode/blob/master/ACKNOWLEDGEMENTS.md).
+- This extension is based on [@skygragon](https://github.com/skygragon)'s [leetcode-cli](https://github.com/skygragon/leetcode-cli) open source project.
+- Special thanks to our [contributors](https://github.com/jdneo/vscode-leetcode/blob/master/ACKNOWLEDGEMENTS.md).
diff --git a/docs/README_zh-CN.md b/docs/README_zh-CN.md
index 8aced3a8..d4baf996 100644
--- a/docs/README_zh-CN.md
+++ b/docs/README_zh-CN.md
@@ -1,6 +1,12 @@
-# LeetCode
+# Debug LeetCode
-> 在 VS Code 中练习 LeetCode
+## 关于为什么发布另一个 vscode leetcode 插件.
+
+See [issue](https://github.com/jdneo/vscode-leetcode/issues/241) and [PR](https://github.com/jdneo/vscode-leetcode/pull/525)
+
+如果你想要用这个插件,你可能需要卸载另外一个,否则他们会有冲突。
+
+> 在 VS Code 中练习 LeetCode 并且愉快调试
@@ -20,21 +26,22 @@
-- [English Document](https://github.com/jdneo/vscode-leetcode#requirements) | 中文文档
+- [English Document](https://github.com/jdneo/vscode-leetcode#requirements) | 中文文档
## ❗️ 注意 ❗️- 无法登录 LeetCode 节点的临时解决办法
+
> 注意:如果使用的是 `leetcode-cn.com` 账户,可以跳过此段落。
近期我们发现插件出现了[无法登录 leetcode.com 节点的问题](https://github.com/jdneo/vscode-leetcode/issues/478)。原因是因为近期 leetcode.com 改变了登录机制,目前我们暂时没有找到解决该问题的完美解决方案。
感谢 [@yihong0618](https://github.com/yihong0618) 提供了一个临时解决办法。现在你可以直接点击登录按钮并选择第三方登录或者 `Cookie` 登录。
-
> 注意:如果你希望使用第三方登录(**推荐**),请确保你的账户已经与第三方账户连接。如果你希望通过 `Cookie` 登录,请点击[该连接](https://github.com/jdneo/vscode-leetcode/issues/478#issuecomment-564757098)查看登录步骤。
## 运行条件
-- [VS Code 1.23.0+](https://code.visualstudio.com/)
-- [Node.js 8+](https://nodejs.org)
+
+- [VS Code 1.23.0+](https://code.visualstudio.com/)
+- [Node.js 8+](https://nodejs.org)
> 注意:请确保`Node`在`PATH`环境变量中。您也可以通过设定 `leetcode.nodePath` 选项来指定 `Node.js` 可执行文件的路径。
## 快速开始
@@ -44,97 +51,152 @@
## 功能
### 登入登出
+
-- 点击 `LeetCode Explorer` 中的 `Sign in to LeetCode` 即可登入。
+- 点击 `LeetCode Explorer` 中的 `Sign in to LeetCode` 即可登入。
+
+- 你也可以使用下来命令登入或利用 cookie 登入或登出:
+ - **LeetCode: Sign in**
+ - **LeetCode: Sign out**
-- 你也可以使用下来命令登入或利用cookie登入或登出:
- - **LeetCode: Sign in**
- - **LeetCode: Sign out**
---
### 切换 LeetCode 版本
+
-- LeetCode 目前有**英文版**和**中文版**两种版本。点击 `LeetCode Explorer` 导航栏中的  按钮可切换版本。
+- LeetCode 目前有**英文版**和**中文版**两种版本。点击 `LeetCode Explorer` 导航栏中的  按钮可切换版本。
+
+- 目前可切换的版本有:
-- 目前可切换的版本有:
- - **leetcode.com**
- - **leetcode-cn.com**
+ - **leetcode.com**
+ - **leetcode-cn.com**
- > 注意:两种版本的 LeetCode 账户并**不通用**,请确保当前激活的版本是正确的。插件默认激活的是**英文版**。
+ > 注意:两种版本的 LeetCode 账户并**不通用**,请确保当前激活的版本是正确的。插件默认激活的是**英文版**。
---
### 选择题目
+
-- 直接点击题目或者在 `LeetCode Explorer` 中**右键**题目并选择 `Preview Problem` 可查看题目描述
-- 选择 `Show Problem` 可直接进行答题。
+- 直接点击题目或者在 `LeetCode Explorer` 中**右键**题目并选择 `Preview Problem` 可查看题目描述
+- 选择 `Show Problem` 可直接进行答题。
- > 注意:你可以通过更新配置项 `leetcode.workspaceFolder` 来指定保存题目文件所用的工作区路径。默认工作区路径为:**$HOME/.leetcode/**。
+ > 注意:你可以通过更新配置项 `leetcode.workspaceFolder` 来指定保存题目文件所用的工作区路径。默认工作区路径为:**\$HOME/.leetcode/**。
- > 注意:你可以通过更新配置项 `leetcode.showCommentDescription` 来指定是否要在注释中包含题目描述。
+ > 注意:你可以通过更新配置项 `leetcode.showCommentDescription` 来指定是否要在注释中包含题目描述。
- > 注意:你可以通过 `LeetCode: Switch Default Language` 命令变更答题时默认使用编程语言。
+ > 注意:你可以通过 `LeetCode: Switch Default Language` 命令变更答题时默认使用编程语言。
+
+---
+
+### 调试题目
+
+
+
+> 当前 vscode-leetcode 仅仅支持 Python3 和 Javascript 语言,未来我们会支持更多支持 vscode debug protocal 的语言, 欢迎大家踊跃 PR 其他语言,我的下一步计划是支持c和c++
+
+> 不是所有的题目都支持(支持大部分免费题目),只有支持的题目才有调试选项
+
+> 如果你有关于调试功能的任何问题,欢迎[创建issue](https://github.com/wangtao0101/vscode-leetcode/issues/new?template=bug.md)
+
+- Python3 调试的必要条件
+
+ - 步骤 1. 在系统上安装对应版本的 python3 (注意: 系统安装的 Python 不支持)。
+
+ - Step 2. 安装 vscode 的 Python 插件。
+
+- Javasript 调试的必要条件
+
+ 无
+
+# 小心 ❗️
+
+插件会在当前文件中生成一些桩代码,例如:
+
+For python:
+
+```python
+# @before-stub-for-debug-begin
+from python3problem1 import *
+from typing import *
+# @before-stub-for-debug-end
+```
+
+For javascript
+
+```js
+// @after-stub-for-debug-begin
+module.exports = twoSum;
+// @after-stub-for-debug-end
+```
+
+如果你一不小心删除了一些桩代码并且忘记还原了,你可以彻底删除所有的桩代码,插件会在下次 debug 的时候重新生成.
---
### 编辑器快捷方式
+
-- 插件会在编辑区域内支持四种不同的快捷方式(Code Lens):
- - `Submit`: 提交你的答案至 LeetCode;
- - `Test`: 用给定的测试用例测试你的答案;
- - `Solution`: 显示该问题的高票解答;
- - `Description`: 显示该问题的题目描述。
+- 插件会在编辑区域内支持四种不同的快捷方式(Code Lens):
- > 注意:你可以通过 `leetcode.editor.shortcuts` 配置项来定制需要激活的快捷方式。默认情况下只有 `Submit` 和 `Test` 会被激活。
+ - `Submit`: 提交你的答案至 LeetCode;
+ - `Test`: 用给定的测试用例测试你的答案;
+ - `Solution`: 显示该问题的高票解答;
+ - `Description`: 显示该问题的题目描述。
+
+ > 注意:你可以通过 `leetcode.editor.shortcuts` 配置项来定制需要激活的快捷方式。默认情况下只有 `Submit` 和 `Test` 会被激活。
---
### 通过关键字搜索题目
+
-- 点击 `LeetCode Explorer` 导航栏中的  按钮可按照关键字搜索题目。
+- 点击 `LeetCode Explorer` 导航栏中的  按钮可按照关键字搜索题目。
---
### 管理存档
+
-- 点击位于 VS Code 底部状态栏的 `LeetCode: ***` 管理 `LeetCode 存档`。你可以**切换**存档或者**创建**,**删除**存档。
-
+- 点击位于 VS Code 底部状态栏的 `LeetCode: ***` 管理 `LeetCode 存档`。你可以**切换**存档或者**创建**,**删除**存档。
## 插件配置项
-| 配置项名称 | 描述 | 默认值 |
-| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
-| `leetcode.hideSolved` | 指定是否要隐藏已解决的问题 | `false` |
-| `leetcode.showLocked` | 指定是否显示付费题目,只有付费账户才可以打开付费题目 | `false` |
-| `leetcode.defaultLanguage` | 指定答题时使用的默认语言,可选语言有:`bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`, `rust`, `scala`,`swift` | `N/A` |
-| `leetcode.useWsl` | 指定是否启用 WSL | `false` |
-| `leetcode.endpoint` | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | `leetcode` |
-| `leetcode.workspaceFolder` | 指定保存文件的工作区目录 | `""` |
-| `leetcode.filePath` | 指定生成题目文件的相对文件夹路径名和文件名。点击查看[更多详细用法](https://github.com/jdneo/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)。 | |
-| `leetcode.enableStatusBar` | 指定是否在 VS Code 下方显示插件状态栏。 | `true` |
-| `leetcode.editor.shortcuts` | 指定在编辑器内所自定义的快捷方式。可用的快捷方式有: `submit`, `test`, `solution`, `description`。 | `["submit, test"]` |
-| `leetcode.enableSideMode` | 指定在解决一道题时,是否将`问题预览`、`高票答案`与`提交结果`窗口集中在编辑器的第二栏。 | `true` |
-| `leetcode.nodePath` | 指定 `Node.js` 可执行文件的路径。如:C:\Program Files\nodejs\node.exe | `node` |
-| `leetcode.showCommentDescription` | 指定是否要在注释中显示题干。 | `false` |
+
+| 配置项名称 | 描述 | 默认值 |
+| --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
+| `leetcode.hideSolved` | 指定是否要隐藏已解决的问题 | `false` |
+| `leetcode.showLocked` | 指定是否显示付费题目,只有付费账户才可以打开付费题目 | `false` |
+| `leetcode.defaultLanguage` | 指定答题时使用的默认语言,可选语言有:`bash`, `c`, `cpp`, `csharp`, `golang`, `java`, `javascript`, `kotlin`, `mysql`, `php`, `python`,`python3`,`ruby`, `rust`, `scala`,`swift` | `N/A` |
+| `leetcode.useWsl` | 指定是否启用 WSL | `false` |
+| `leetcode.endpoint` | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | `leetcode` |
+| `leetcode.workspaceFolder` | 指定保存文件的工作区目录 | `""` |
+| `leetcode.filePath` | 指定生成题目文件的相对文件夹路径名和文件名。点击查看[更多详细用法](https://github.com/jdneo/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)。 | |
+| `leetcode.enableStatusBar` | 指定是否在 VS Code 下方显示插件状态栏。 | `true` |
+| `leetcode.editor.shortcuts` | 指定在编辑器内所自定义的快捷方式。可用的快捷方式有: `submit`, `test`, `solution`, `description`。 | `["submit, test"]` |
+| `leetcode.enableSideMode` | 指定在解决一道题时,是否将`问题预览`、`高票答案`与`提交结果`窗口集中在编辑器的第二栏。 | `true` |
+| `leetcode.nodePath` | 指定 `Node.js` 可执行文件的路径。如:C:\Program Files\nodejs\node.exe | `node` |
+| `leetcode.showCommentDescription` | 指定是否要在注释中显示题干。 | `false` |
## 需要帮助?
+
在遇到任何问题时,可以先查看一下[疑难解答](https://github.com/jdneo/vscode-leetcode/wiki/%E7%96%91%E9%9A%BE%E8%A7%A3%E7%AD%94)以及[常见问题](https://github.com/jdneo/vscode-leetcode/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)寻求帮助。
如果您的问题依然没有解决,可以在 [Gitter Channel](https://gitter.im/vscode-leetcode/Lobby) 联系我们,或者您也可以[记录一个新的 issue](https://github.com/jdneo/vscode-leetcode/issues/new/choose)。
@@ -145,5 +207,5 @@
## 鸣谢
-- 本插件基于[@skygragon](https://github.com/skygragon)的[leetcode-cli](https://github.com/skygragon/leetcode-cli)开源项目制作。
-- 特别鸣谢这些[贡献者们](https://github.com/jdneo/vscode-leetcode/blob/master/ACKNOWLEDGEMENTS.md)。
+- 本插件基于[@skygragon](https://github.com/skygragon)的[leetcode-cli](https://github.com/skygragon/leetcode-cli)开源项目制作。
+- 特别鸣谢这些[贡献者们](https://github.com/jdneo/vscode-leetcode/blob/master/ACKNOWLEDGEMENTS.md)。
diff --git a/docs/gifs/debug.gif b/docs/gifs/debug.gif
new file mode 100644
index 00000000..95b506eb
Binary files /dev/null and b/docs/gifs/debug.gif differ
diff --git a/package-lock.json b/package-lock.json
index 0a555853..bd8dfb15 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -73,8 +73,7 @@
"acorn": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-2.7.0.tgz",
- "integrity": "sha1-q259nYhqrKiwhbwzEreaGYQz8Oc=",
- "optional": true
+ "integrity": "sha1-q259nYhqrKiwhbwzEreaGYQz8Oc="
},
"acorn-globals": {
"version": "1.0.9",
@@ -417,8 +416,7 @@
"diff": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
- "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
- "dev": true
+ "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA=="
},
"dom-serializer": {
"version": "0.1.1",
@@ -853,6 +851,11 @@
"invert-kv": "^1.0.0"
}
},
+ "leetcode-problem-types": {
+ "version": "0.1.0",
+ "resolved": "https://registry.npm.taobao.org/leetcode-problem-types/download/leetcode-problem-types-0.1.0.tgz",
+ "integrity": "sha1-RiC6OrmqMUR8IWuwRLm++vrgd/A="
+ },
"levn": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
@@ -1195,8 +1198,7 @@
"prelude-ls": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
- "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=",
- "optional": true
+ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ="
},
"prompt": {
"version": "1.0.0",
@@ -1539,7 +1541,6 @@
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz",
"integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=",
- "optional": true,
"requires": {
"prelude-ls": "~1.1.2"
}
diff --git a/package.json b/package.json
index ddc54134..2577699a 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,10 @@
{
- "name": "vscode-leetcode",
- "displayName": "LeetCode",
- "description": "Solve LeetCode problems in VS Code",
- "version": "0.16.1",
- "author": "Sheng Chen",
- "publisher": "shengchen",
+ "name": "debug-leetcode",
+ "displayName": "Debug LeetCode",
+ "description": "Solve LeetCode problems in VS Code and enjoy debugging",
+ "version": "0.1.1",
+ "author": "wangtao0101",
+ "publisher": "wangtao0101",
"license": "MIT",
"icon": "resources/LeetCode.png",
"engines": {
@@ -12,9 +12,9 @@
},
"repository": {
"type": "git",
- "url": "https://github.com/jdneo/vscode-leetcode"
+ "url": "https://github.com/wangtao0101/vscode-leetcode"
},
- "homepage": "https://github.com/jdneo/vscode-leetcode/blob/master/README.md",
+ "homepage": "https://github.com/wangtao0101/vscode-leetcode/blob/master/README.md",
"categories": [
"Other",
"Snippets"
diff --git a/src/commands/test.ts b/src/commands/test.ts
index d070c9aa..ed4daa42 100644
--- a/src/commands/test.ts
+++ b/src/commands/test.ts
@@ -1,17 +1,21 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.
+import * as fs from "fs";
import * as fse from "fs-extra";
import * as vscode from "vscode";
+import { debugExecutor } from "../debug/debugExecutor";
+import problemTypes from "../debug/problemTypes";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { leetCodeManager } from "../leetCodeManager";
import { IQuickItemEx, UserStatus } from "../shared";
-import { isWindows, usingCmd } from "../utils/osUtils";
+import { fileMeta, parseTestString } from "../utils/problemUtils";
import { DialogType, promptForOpenOutputChannel, showFileSelectDialog } from "../utils/uiUtils";
import { getActiveFilePath } from "../utils/workspaceUtils";
-import * as wsl from "../utils/wslUtils";
import { leetCodeSubmissionProvider } from "../webview/leetCodeSubmissionProvider";
+const supportDebugLanguages: string[] = ["javascript", "python3", "cpp"];
+
export async function testSolution(uri?: vscode.Uri): Promise {
try {
if (leetCodeManager.getStatus() === UserStatus.SignedOut) {
@@ -43,6 +47,25 @@ export async function testSolution(uri?: vscode.Uri): Promise {
value: ":file",
},
);
+
+ const fileContent: Buffer = fs.readFileSync(filePath);
+ const meta: { id: string; lang: string } | null = fileMeta(fileContent.toString());
+
+ if (meta != null && supportDebugLanguages.indexOf(meta.lang) !== -1 && problemTypes[meta.id] != null) {
+ picks.push({
+ label: "$(three-bars) Debug by default test cases",
+ description: "",
+ detail: "Debug by default test cases",
+ value: ":debug-default",
+ });
+ picks.push({
+ label: "$(pencil) Debug by writing directly...",
+ description: "",
+ detail: "Debug by writing test cases in input box",
+ value: ":debug-direct",
+ });
+ }
+
const choice: IQuickItemEx | undefined = await vscode.window.showQuickPick(picks);
if (!choice) {
return;
@@ -56,7 +79,8 @@ export async function testSolution(uri?: vscode.Uri): Promise {
case ":direct":
const testString: string | undefined = await vscode.window.showInputBox({
prompt: "Enter the test cases.",
- validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "Test case must not be empty.",
+ validateInput: (s: string): string | undefined =>
+ s && s.trim() ? undefined : "Test case must not be empty.",
placeHolder: "Example: [1,2,3]\\n4",
ignoreFocusOut: true,
});
@@ -69,12 +93,34 @@ export async function testSolution(uri?: vscode.Uri): Promise {
if (testFile && testFile.length) {
const input: string = (await fse.readFile(testFile[0].fsPath, "utf-8")).trim();
if (input) {
- result = await leetCodeExecutor.testSolution(filePath, parseTestString(input.replace(/\r?\n/g, "\\n")));
+ result = await leetCodeExecutor.testSolution(
+ filePath,
+ parseTestString(input.replace(/\r?\n/g, "\\n")),
+ );
} else {
vscode.window.showErrorMessage("The selected test file must not be empty.");
}
}
break;
+ case ":debug-default":
+ result = await debugExecutor.execute(
+ filePath,
+ problemTypes[meta!.id]!.testCase.replace(/"/g, '\\"'),
+ meta!.lang,
+ );
+ break;
+ case ":debug-direct":
+ const ts: string | undefined = await vscode.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);
+ }
+ break;
default:
break;
}
@@ -83,20 +129,9 @@ export async function testSolution(uri?: vscode.Uri): Promise {
}
leetCodeSubmissionProvider.show(result);
} catch (error) {
- await promptForOpenOutputChannel("Failed to test the solution. Please open the output channel for details.", DialogType.error);
- }
-}
-
-function parseTestString(test: string): string {
- if (wsl.useWsl() || !isWindows()) {
- return `'${test}'`;
- }
-
- // In windows and not using WSL
- if (usingCmd()) {
- return `"${test.replace(/"/g, '\\"')}"`;
- } else {
- // Assume using PowerShell
- return `'${test.replace(/"/g, '\\"')}'`;
+ await promptForOpenOutputChannel(
+ "Failed to test the solution. Please open the output channel for details.",
+ DialogType.error,
+ );
}
}
diff --git a/src/debug/debugExecutor.ts b/src/debug/debugExecutor.ts
new file mode 100644
index 00000000..0e4e1a27
--- /dev/null
+++ b/src/debug/debugExecutor.ts
@@ -0,0 +1,189 @@
+import * as fse from "fs-extra";
+import * as net from "net";
+// import * as path from "path";
+import * as vscode from "vscode";
+import { leetCodeChannel } from "../leetCodeChannel";
+import { leetCodeExecutor } from "../leetCodeExecutor";
+import { fileMeta, getEntryFile, parseTestString } from "../utils/problemUtils";
+import { leetCodeSubmissionProvider } from "../webview/leetCodeSubmissionProvider";
+import { cppExecutor } from "./executor/cppExecutor";
+import problemTypes from "./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().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().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) => {
+ leetCodeChannel.appendLine(error.toString());
+ });
+ });
+
+ this.server.on("error", (error: Error) => {
+ leetCodeChannel.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 00000000..9dd4dbf5
--- /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 00000000..5c09efa1
--- /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 00000000..a684acaa
--- /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 00000000..a23a9cc6
--- /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 00000000..69dbceac
--- /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 00000000..23b4444a
--- /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 00000000..8845622b
--- /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 00000000..b5d5def2
--- /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 00000000..c0890947
--- /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 00000000..69372a6b
--- /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 00000000..11ae1344
--- /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 00000000..a06b0974
--- /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 00000000..d8c448d1
--- /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 00000000..c4c52847
--- /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 00000000..c921394a
--- /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(int x) : val(x), next(NULL)
+ {
+ }
+};
+
+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 *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 00000000..a9a326df
--- /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 00000000..c7feabf9
--- /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 00000000..a8be77a9
--- /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 00000000..039112d2
--- /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 00000000..b123b317
--- /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 00000000..709b1be4
--- /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 00000000..6e14d71b
--- /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 00000000..d1ef8c0d
--- /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 00000000..6b365d37
--- /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 00000000..6b365d37
--- /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 00000000..6b365d37
--- /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 00000000..6b365d37
--- /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 00000000..283eb632
--- /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 00000000..b41768c9
--- /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 00000000..fd1aab30
--- /dev/null
+++ b/src/debug/entry/python3/entry.py
@@ -0,0 +1,229 @@
+import importlib.util
+import sys
+from pathlib import Path
+import json
+import re
+import socket
+
+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
+
+
+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
+
+
+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),
+ }
+ 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():
+ module = loadModule()
+ solution = module.Solution()
+ func = getattr(solution, funcName)
+
+ lines = testString.split("\\n")
+
+ params = []
+ for i, val in enumerate(lines):
+ params.append(json.loads(val))
+
+ 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.js b/src/debug/entry/python3/problems/1095.js
new file mode 100644
index 00000000..e1e59be3
--- /dev/null
+++ b/src/debug/entry/python3/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/python3/problems/116.py b/src/debug/entry/python3/problems/116.py
new file mode 100644
index 00000000..bb95be52
--- /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 00000000..d4db2669
--- /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 00000000..0ae22a40
--- /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 00000000..559c6e63
--- /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 00000000..057372b5
--- /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/341.py b/src/debug/entry/python3/problems/341.py
new file mode 100644
index 00000000..c11c6f1a
--- /dev/null
+++ b/src/debug/entry/python3/problems/341.py
@@ -0,0 +1,15 @@
+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))
+
+ i, v = func(newParams[0]), []
+ while i.hasNext():
+ v.append(i.next())
+
+
+def parseSpecialParameter(index, type, 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 00000000..cacc9d31
--- /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 00000000..cacc9d31
--- /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 00000000..cacc9d31
--- /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 00000000..cacc9d31
--- /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.js b/src/debug/entry/python3/problems/843.js
new file mode 100644
index 00000000..a5774b09
--- /dev/null
+++ b/src/debug/entry/python3/problems/843.js
@@ -0,0 +1,26 @@
+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/python3/problems/common.py b/src/debug/entry/python3/problems/common.py
new file mode 100644
index 00000000..2112df21
--- /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 00000000..5989082e
--- /dev/null
+++ b/src/debug/executor/cppExecutor.ts
@@ -0,0 +1,336 @@
+import * as fse from "fs-extra";
+import * as path from "path";
+import * as vscode from "vscode";
+import { extensionState } from "../../extensionState";
+import { leetCodeChannel } from "../../leetCodeChannel";
+import { executeCommand } from "../../utils/cpUtils";
+import { fileMeta, getEntryFile, getProblemSpecialCode, randomString } from "../../utils/problemUtils";
+import { IDebugConfig, IProblemType } from "../debugExecutor";
+import problemTypes from "../problemTypes";
+
+const debugConfig: IDebugConfig = {
+ type: "cppdbg",
+ MIMode: "gdb",
+ setupCommands: [
+ {
+ description: "Enable pretty-printing for gdb",
+ text: "-enable-pretty-printing",
+ ignoreFailures: true,
+ },
+ ],
+ miDebuggerPath: "gdb.exe",
+};
+
+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;
+ }
+
+ debugConfig.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
+#include
+#include
+#include "${commonHeaderName}"
+
+using namespace std;
+// @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 = debugConfig.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("wangtao0101.debug-leetcode")!.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");
+
+ try {
+ const includePath: string = path.dirname(exePath);
+ await executeCommand("g++.exe -g", [
+ `${debugConfig.program} ${commonDestPath} ${jsonPath} -o ${exePath} -I ${includePath} -I ${thirdPartyPath}`,
+ ]);
+ } catch (e) {
+ // vscode.window.showErrorMessage(e);
+ leetCodeChannel.show();
+ return;
+ }
+
+ debugConfig.program = exePath;
+ debugConfig.cwd = extensionState.cachePath;
+ // map build source file to user source file
+ debugConfig.sourceFileMap = {
+ [newSourceFilePath]: filePath,
+ };
+
+ 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;
+ }
+}
+
+export const cppExecutor: CppExecutor = new CppExecutor();
diff --git a/src/debug/problemTypes.ts b/src/debug/problemTypes.ts
new file mode 100644
index 00000000..ce1f4f38
--- /dev/null
+++ b/src/debug/problemTypes.ts
@@ -0,0 +1,5321 @@
+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/debug/thirdparty/c/cJSON.c b/src/debug/thirdparty/c/cJSON.c
new file mode 100644
index 00000000..713334c1
--- /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 00000000..21099b48
--- /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 9bb3ad41..1a6e25f9 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -14,11 +14,13 @@ import * as test from "./commands/test";
import { explorerNodeManager } from "./explorer/explorerNodeManager";
import { LeetCodeNode } from "./explorer/LeetCodeNode";
import { leetCodeTreeDataProvider } from "./explorer/LeetCodeTreeDataProvider";
+import { extensionState } from "./extensionState";
import { leetCodeChannel } from "./leetCodeChannel";
import { leetCodeExecutor } from "./leetCodeExecutor";
import { leetCodeManager } from "./leetCodeManager";
import { leetCodeStatusBarController } from "./statusbar/leetCodeStatusBarController";
import { DialogType, promptForOpenOutputChannel } from "./utils/uiUtils";
+import { checkCachePath } from "./utils/workspaceUtils";
import { leetCodePreviewProvider } from "./webview/leetCodePreviewProvider";
import { leetCodeSolutionProvider } from "./webview/leetCodeSolutionProvider";
import { leetCodeSubmissionProvider } from "./webview/leetCodeSubmissionProvider";
@@ -26,6 +28,10 @@ import { markdownEngine } from "./webview/markdownEngine";
export async function activate(context: vscode.ExtensionContext): Promise {
try {
+ extensionState.context = context;
+ extensionState.cachePath = context.globalStoragePath;
+ checkCachePath(extensionState.cachePath);
+
if (!await leetCodeExecutor.meetRequirements()) {
throw new Error("The environment doesn't meet requirements.");
}
diff --git a/src/extensionState.ts b/src/extensionState.ts
new file mode 100644
index 00000000..668b9ecc
--- /dev/null
+++ b/src/extensionState.ts
@@ -0,0 +1,11 @@
+import * as vscode from "vscode";
+
+interface IExtensionState {
+ context: vscode.ExtensionContext;
+ cachePath: string;
+}
+
+export const extensionState: IExtensionState = {
+ context: (null as any),
+ cachePath: "",
+};
diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts
index 4c0aa312..6f5f0cce 100644
--- a/src/leetCodeExecutor.ts
+++ b/src/leetCodeExecutor.ts
@@ -8,6 +8,7 @@ import * as requireFromString from "require-from-string";
import { ConfigurationChangeEvent, Disposable, MessageItem, window, workspace, WorkspaceConfiguration } from "vscode";
import { Endpoint, IProblem, supportedPlugins } from "./shared";
import { executeCommand, executeCommandWithProgress } from "./utils/cpUtils";
+import { getUnstubedFile } from "./utils/problemUtils";
import { DialogOptions, openUrl } from "./utils/uiUtils";
import * as wsl from "./utils/wslUtils";
import { toWslPath, useWsl } from "./utils/wslUtils";
@@ -36,7 +37,7 @@ class LeetCodeExecutor implements Disposable {
public async meetRequirements(): Promise {
if (this.nodeExecutable !== "node") {
- if (!await fse.pathExists(this.nodeExecutable)) {
+ if (!(await fse.pathExists(this.nodeExecutable))) {
throw new Error(`The Node.js executable does not exist on path ${this.nodeExecutable}`);
}
// Wrap the executable with "" to avoid space issue in the path.
@@ -58,10 +59,22 @@ class LeetCodeExecutor implements Disposable {
return false;
}
for (const plugin of supportedPlugins) {
- try { // Check plugin
- await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-e", plugin]);
- } catch (error) { // Download plugin and activate
- await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-i", plugin]);
+ try {
+ // Check plugin
+ await this.executeCommandEx(this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "plugin",
+ "-e",
+ plugin,
+ ]);
+ } catch (error) {
+ // Download plugin and activate
+ await this.executeCommandEx(this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "plugin",
+ "-i",
+ plugin,
+ ]);
}
}
return true;
@@ -76,33 +89,57 @@ class LeetCodeExecutor implements Disposable {
}
public async signOut(): Promise {
- return await await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "user", "-L"]);
+ return await await this.executeCommandEx(this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "user",
+ "-L",
+ ]);
}
public async listProblems(showLocked: boolean): Promise {
- return await this.executeCommandEx(this.nodeExecutable, showLocked ?
- [await this.getLeetCodeBinaryPath(), "list"] :
- [await this.getLeetCodeBinaryPath(), "list", "-q", "L"],
+ return await this.executeCommandEx(
+ this.nodeExecutable,
+ showLocked
+ ? [await this.getLeetCodeBinaryPath(), "list"]
+ : [await this.getLeetCodeBinaryPath(), "list", "-q", "L"],
);
}
- public async showProblem(problemNode: IProblem, language: string, filePath: string, showDescriptionInComment: boolean = false): Promise {
+ public async showProblem(
+ problemNode: IProblem,
+ language: string,
+ filePath: string,
+ showDescriptionInComment: boolean = false,
+ ): Promise {
const templateType: string = showDescriptionInComment ? "-cx" : "-c";
- if (!await fse.pathExists(filePath)) {
+ if (!(await fse.pathExists(filePath))) {
await fse.createFile(filePath);
- const codeTemplate: string = await this.executeCommandWithProgressEx("Fetching problem data...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "show", problemNode.id, templateType, "-l", language]);
+ const codeTemplate: string = await this.executeCommandWithProgressEx(
+ "Fetching problem data...",
+ this.nodeExecutable,
+ [await this.getLeetCodeBinaryPath(), "show", problemNode.id, templateType, "-l", language],
+ );
await fse.writeFile(filePath, codeTemplate);
}
}
public async showSolution(input: string, language: string): Promise {
- const solution: string = await this.executeCommandWithProgressEx("Fetching top voted solution from discussions...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "show", input, "--solution", "-l", language]);
+ const solution: string = await this.executeCommandWithProgressEx(
+ "Fetching top voted solution from discussions...",
+ this.nodeExecutable,
+ [await this.getLeetCodeBinaryPath(), "show", input, "--solution", "-l", language],
+ );
return solution;
}
public async getDescription(problemNodeId: string): Promise {
- return await this.executeCommandWithProgressEx("Fetching problem description...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "show", problemNodeId, "-x"]);
+ return await this.executeCommandWithProgressEx("Fetching problem description...", this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "show",
+ problemNodeId,
+ "-x",
+ ]);
}
public async listSessions(): Promise {
@@ -110,20 +147,40 @@ class LeetCodeExecutor implements Disposable {
}
public async enableSession(name: string): Promise {
- return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "session", "-e", name]);
+ return await this.executeCommandEx(this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "session",
+ "-e",
+ name,
+ ]);
}
public async createSession(id: string): Promise {
- return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "session", "-c", id]);
+ return await this.executeCommandEx(this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "session",
+ "-c",
+ id,
+ ]);
}
public async deleteSession(id: string): Promise {
- return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "session", "-d", id]);
+ return await this.executeCommandEx(this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "session",
+ "-d",
+ id,
+ ]);
}
public async submitSolution(filePath: string): Promise {
+ const newPath: string = await getUnstubedFile(filePath);
try {
- return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "submit", `"${filePath}"`]);
+ return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "submit",
+ `"${newPath}"`,
+ ]);
} catch (error) {
if (error.result) {
return error.result;
@@ -133,19 +190,40 @@ class LeetCodeExecutor implements Disposable {
}
public async testSolution(filePath: string, testString?: string): Promise {
+ const newPath: string = await getUnstubedFile(filePath);
if (testString) {
- return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`, "-t", `${testString}`]);
+ return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "test",
+ `"${newPath}"`,
+ "-t",
+ `${testString}`,
+ ]);
}
- return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`]);
+ return await this.executeCommandWithProgressEx("Submitting to LeetCode...", this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "test",
+ `"${newPath}"`,
+ ]);
}
public async switchEndpoint(endpoint: string): Promise {
switch (endpoint) {
case Endpoint.LeetCodeCN:
- return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-e", "leetcode.cn"]);
+ return await this.executeCommandEx(this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "plugin",
+ "-e",
+ "leetcode.cn",
+ ]);
case Endpoint.LeetCode:
default:
- return await this.executeCommandEx(this.nodeExecutable, [await this.getLeetCodeBinaryPath(), "plugin", "-d", "leetcode.cn"]);
+ return await this.executeCommandEx(this.nodeExecutable, [
+ await this.getLeetCodeBinaryPath(),
+ "plugin",
+ "-d",
+ "leetcode.cn",
+ ]);
}
}
@@ -157,7 +235,10 @@ class LeetCodeExecutor implements Disposable {
await this.executeCommandWithProgressEx("Updating the favorite list...", "node", commandParams);
}
- public async getCompaniesAndTags(): Promise<{ companies: { [key: string]: string[] }, tags: { [key: string]: string[] } }> {
+ public async getCompaniesAndTags(): Promise<{
+ companies: { [key: string]: string[] };
+ tags: { [key: string]: string[] };
+ }> {
// preprocess the plugin source
const companiesTagsPath: string = path.join(this.leetCodeRootPath, "lib", "plugins", "company.js");
const companiesTagsSrc: string = (await fse.readFile(companiesTagsPath, "utf8")).replace(
@@ -181,14 +262,23 @@ class LeetCodeExecutor implements Disposable {
return extensionConfig.get("nodePath", "node" /* default value */);
}
- private async executeCommandEx(command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise {
+ private async executeCommandEx(
+ command: string,
+ args: string[],
+ options: cp.SpawnOptions = { shell: true },
+ ): Promise {
if (wsl.useWsl()) {
return await executeCommand("wsl", [command].concat(args), options);
}
return await executeCommand(command, args, options);
}
- private async executeCommandWithProgressEx(message: string, command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise {
+ private async executeCommandWithProgressEx(
+ message: string,
+ command: string,
+ args: string[],
+ options: cp.SpawnOptions = { shell: true },
+ ): Promise {
if (wsl.useWsl()) {
return await executeCommandWithProgress(message, "wsl", [command].concat(args), options);
}
diff --git a/src/utils/problemUtils.ts b/src/utils/problemUtils.ts
index d2dcc3ed..aee2066f 100644
--- a/src/utils/problemUtils.ts
+++ b/src/utils/problemUtils.ts
@@ -1,36 +1,137 @@
-// Copyright (c) jdneo. All rights reserved.
-// Licensed under the MIT license.
-
-import * as fse from "fs-extra";
-import * as _ from "lodash";
-import * as path from "path";
-import { IProblem, langExt } from "../shared";
-
-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 genFileName(node: IProblem, language: string): string {
- const slug: string = _.kebabCase(node.name);
- const ext: string = genFileExt(language);
- return `${node.id}.${slug}.${ext}`;
-}
-
-export async function getNodeIdFromFile(fsPath: string): Promise {
- const fileContent: string = await fse.readFile(fsPath, "utf8");
- let id: string = "";
- const matchResults: RegExpMatchArray | null = fileContent.match(/@lc.+id=(.+?) /);
- if (matchResults && matchResults.length === 2) {
- id = matchResults[1];
- }
- // Try to get id from file name if getting from comments failed
- if (!id) {
- id = path.basename(fsPath).split(".")[0];
- }
-
- return id;
-}
+// Copyright (c) jdneo. All rights reserved.
+// Licensed under the MIT license.
+
+import * as fse from "fs-extra";
+import * as _ from "lodash";
+import * as path from "path";
+import * as vscode from "vscode";
+import { extensionState } from "../extensionState";
+import { IProblem, langExt } from "../shared";
+import { isWindows, usingCmd } from "./osUtils";
+import { useWsl } from "./wslUtils";
+
+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/;
+
+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 genFileName(node: IProblem, language: string): string {
+ const slug: string = _.kebabCase(node.name);
+ const ext: string = genFileExt(language);
+ return `${node.id}.${slug}.${ext}`;
+}
+
+export async function getNodeIdFromFile(fsPath: string): Promise {
+ const fileContent: string = await fse.readFile(fsPath, "utf8");
+ let id: string = "";
+ const matchResults: RegExpMatchArray | null = fileContent.match(/@lc.+id=(.+?) /);
+ if (matchResults && matchResults.length === 2) {
+ id = matchResults[1];
+ }
+ // Try to get id from file name if getting from comments failed
+ if (!id) {
+ id = path.basename(fsPath).split(".")[0];
+ }
+
+ return id;
+}
+
+export function fileMeta(content: string): { id: string; lang: string } | 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("wangtao0101.debug-leetcode")!.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;
+}
diff --git a/src/utils/workspaceUtils.ts b/src/utils/workspaceUtils.ts
index c129f8db..39b77e97 100644
--- a/src/utils/workspaceUtils.ts
+++ b/src/utils/workspaceUtils.ts
@@ -1,6 +1,7 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.
+import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
@@ -41,13 +42,23 @@ export async function selectWorkspaceFolder(): Promise {
case OpenOption.justOpenFile:
return workspaceFolderSetting;
case OpenOption.openInCurrentWindow:
- await vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(workspaceFolderSetting), false);
+ await vscode.commands.executeCommand(
+ "vscode.openFolder",
+ vscode.Uri.file(workspaceFolderSetting),
+ false,
+ );
return "";
case OpenOption.openInNewWindow:
- await vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(workspaceFolderSetting), true);
+ await vscode.commands.executeCommand(
+ "vscode.openFolder",
+ vscode.Uri.file(workspaceFolderSetting),
+ true,
+ );
return "";
case OpenOption.addToWorkspace:
- vscode.workspace.updateWorkspaceFolders(workspaceFolders.length, 0, { uri: vscode.Uri.file(workspaceFolderSetting) });
+ vscode.workspace.updateWorkspaceFolders(workspaceFolders.length, 0, {
+ uri: vscode.Uri.file(workspaceFolderSetting),
+ });
break;
default:
return "";
@@ -68,7 +79,7 @@ export async function getActiveFilePath(uri?: vscode.Uri): Promise {
value: ":browse",
},
);
- const choice: IQuickItemEx | undefined = await vscode.window.showQuickPick(
- picks,
- { placeHolder: "Select where you would like to save your LeetCode files" },
- );
+ const choice: IQuickItemEx | undefined = await vscode.window.showQuickPick(picks, {
+ placeHolder: "Select where you would like to save your LeetCode files",
+ });
if (!choice) {
result = "";
} else if (choice.value === ":browse") {
@@ -125,3 +135,9 @@ enum OpenOption {
openInNewWindow = "Open in new window",
addToWorkspace = "Add to workspace",
}
+
+export function checkCachePath(globalStoragePath: string): void {
+ if (!fs.existsSync(globalStoragePath)) {
+ fs.mkdirSync(globalStoragePath);
+ }
+}
diff --git a/thirdpartynotice.txt b/thirdpartynotice.txt
index 1f33cded..6ca0c142 100644
--- a/thirdpartynotice.txt
+++ b/thirdpartynotice.txt
@@ -1,207 +1,207 @@
-THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
-For vscode-leetcode extension
-
-This extension uses Open Source components. You can find the source code of their
-open source projects along with the license information below. We acknowledge and
-are grateful to these developers for their contribution to open source.
-
-1. fs-extra (https://github.com/jprichardson/node-fs-extra)
-2. highlight.js (https://github.com/highlightjs/highlight.js/)
-3. require-from-string (https://github.com/floatdrop/require-from-string)
-4. lodash (https://github.com/lodash/lodash)
-5. markdown-it (https://github.com/markdown-it/markdown-it)
-6. leetcode-cli (https://github.com/skygragon/leetcode-cli)
-
-fs-extra NOTICES BEGIN HERE
-=============================
-
-(The MIT License)
-
-Copyright (c) 2011-2017 JP Richardson
-
-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.
-
-END OF fs-extra NOTICES AND INFORMATION
-==================================
-
-highlight.js NOTICES BEGIN HERE
-=============================
-
-Copyright (c) 2006, Ivan Sagalaev
-All rights reserved.
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of highlight.js nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-END OF highlight.js NOTICES AND INFORMATION
-==================================
-
-require-from-string NOTICES BEGIN HERE
-=============================
-
-The MIT License (MIT)
-
-Copyright (c) Vsevolod Strukchinsky (github.com/floatdrop)
-
-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.
-
-END OF require-from-string NOTICES AND INFORMATION
-==================================
-
-lodash NOTICES BEGIN HERE
-=============================
-
-The MIT License
-
-Copyright JS Foundation and other contributors
-
-Based on Underscore.js, copyright Jeremy Ashkenas,
-DocumentCloud and Investigative Reporters & Editors
-
-This software consists of voluntary contributions made by many
-individuals. For exact contribution history, see the revision history
-available at https://github.com/lodash/lodash
-
-The following license applies to all parts of this software except as
-documented below:
-
-====
-
-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.
-
-====
-
-Copyright and related rights for sample code are waived via CC0. Sample
-code is defined as all source code displayed within the prose of the
-documentation.
-
-CC0: http://creativecommons.org/publicdomain/zero/1.0/
-
-====
-
-Files located in the node_modules and vendor directories are externally
-maintained libraries used by this software which have their own
-licenses; we recommend you read them, as their terms may differ from the
-terms above.
-
-END OF lodash NOTICES AND INFORMATION
-==================================
-
-markdown-it NOTICES BEGIN HERE
-=============================
-
-Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin.
-
-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.
-
-END OF markdown-it NOTICES AND INFORMATION
-==================================
-
-leetcode-cli NOTICES BEGIN HERE
-=============================
-
-MIT License
-
-Copyright (c) 2016 skygragon
-
-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.
-
-END OF leetcode-cli NOTICES AND INFORMATION
-==================================
+THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
+For debug-leetcode extension
+
+This extension uses Open Source components. You can find the source code of their
+open source projects along with the license information below. We acknowledge and
+are grateful to these developers for their contribution to open source.
+
+1. fs-extra (https://github.com/jprichardson/node-fs-extra)
+2. highlight.js (https://github.com/highlightjs/highlight.js/)
+3. require-from-string (https://github.com/floatdrop/require-from-string)
+4. lodash (https://github.com/lodash/lodash)
+5. markdown-it (https://github.com/markdown-it/markdown-it)
+6. leetcode-cli (https://github.com/skygragon/leetcode-cli)
+
+fs-extra NOTICES BEGIN HERE
+=============================
+
+(The MIT License)
+
+Copyright (c) 2011-2017 JP Richardson
+
+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.
+
+END OF fs-extra NOTICES AND INFORMATION
+==================================
+
+highlight.js NOTICES BEGIN HERE
+=============================
+
+Copyright (c) 2006, Ivan Sagalaev
+All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of highlight.js nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+END OF highlight.js NOTICES AND INFORMATION
+==================================
+
+require-from-string NOTICES BEGIN HERE
+=============================
+
+The MIT License (MIT)
+
+Copyright (c) Vsevolod Strukchinsky (github.com/floatdrop)
+
+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.
+
+END OF require-from-string NOTICES AND INFORMATION
+==================================
+
+lodash NOTICES BEGIN HERE
+=============================
+
+The MIT License
+
+Copyright JS Foundation and other contributors
+
+Based on Underscore.js, copyright Jeremy Ashkenas,
+DocumentCloud and Investigative Reporters & Editors
+
+This software consists of voluntary contributions made by many
+individuals. For exact contribution history, see the revision history
+available at https://github.com/lodash/lodash
+
+The following license applies to all parts of this software except as
+documented below:
+
+====
+
+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.
+
+====
+
+Copyright and related rights for sample code are waived via CC0. Sample
+code is defined as all source code displayed within the prose of the
+documentation.
+
+CC0: http://creativecommons.org/publicdomain/zero/1.0/
+
+====
+
+Files located in the node_modules and vendor directories are externally
+maintained libraries used by this software which have their own
+licenses; we recommend you read them, as their terms may differ from the
+terms above.
+
+END OF lodash NOTICES AND INFORMATION
+==================================
+
+markdown-it NOTICES BEGIN HERE
+=============================
+
+Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin.
+
+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.
+
+END OF markdown-it NOTICES AND INFORMATION
+==================================
+
+leetcode-cli NOTICES BEGIN HERE
+=============================
+
+MIT License
+
+Copyright (c) 2016 skygragon
+
+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.
+
+END OF leetcode-cli NOTICES AND INFORMATION
+==================================