1 Star 0 Fork 0

Gitee 极速下载 / LeetcodeJavaDebugEnhancer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/Jidcoo/LeetcodeJavaDebugEnhancer
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

LeetcodeJavaDebugEnhancer

🚀 一个用于Java的Leetcode算法题的本地调试增强器 🚀

License Maven Build Status Maven Release Status GitHub Release Maven Central Version GitHub Issues

[中文] [English]


🎯 目标

  • 提供方便快速的调试功能。
  • 支持多样的输入源和输出源。
  • 自动适配各种输入参数类型。
  • 提供易维护、易拓展的API接口用于适配更多Leetcode算法调试场景。

🔧 下载与安装

下载

Maven

<dependency>
    <groupId>io.github.jidcoo</groupId>
    <artifactId>leetcode-java-debug-enhancer</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle

implementation 'io.github.jidcoo:leetcode-java-debug-enhancer:1.0.0'

Jar

资源 索引
托管仓库 点击这里浏览本项目的托管仓库
标准-Jar 点击这里直接下载(标准-Jar)
全量-Jar 点击这里直接下载(全量-Jar)

安装

只需把LeetcodeJavaDebugEnhancer作为项目的库引入即可。

运行要求

  • 支持的最低Java版本为Java 8
  • LeetcodeJavaDebugEnhancer依赖于Gson,版本为2.10.1。非Maven、非Gradle项目且项目本身不包含Gson库的,请使用全量-Jar或者手动添加Gson库到项目中。

🛠 基本使用

步骤1:

创建一个名为SimpleTest的Java类,并确保SimpleTest是public的:

//SimpleTest.java

public class SimpleTest {

}

步骤2:

在SimpleTest中导入io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer,并声明SimpleTest继承自类LeetcodeJavaDebugEnhancer

//SimpleTest.java

import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;

public class SimpleTest extends LeetcodeJavaDebugEnhancer {

}

步骤3:

把Leetcode网站上的题目的Java语言代码粘贴到SimpleTest类中并编写相应的算法代码完成题目要求,这里以题目两数之和为例:

//SimpleTest.java

import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;

public class SimpleTest extends LeetcodeJavaDebugEnhancer {
    
    class Solution {
        public int[] twoSum(int[] nums, int target) {
            int n = nums.length;
            for (int i = 0; i < n; ++i) {
                for (int j = i + 1; j < n; ++j) {
                    if (nums[i] + nums[j] == target) {
                        return new int[]{i, j};
                    }
                }
            }
            return new int[0];
        }
    }

}

步骤4:

点击SimpleTest的运行或调试按钮从而运行SimpleTest,启动调试增强器。

增强器启动后你将会看到如下输出:

LeetcodeJavaDebugEnhancer[1.0.0] started.

Case输入规则:一个Case占据一行,下一个Case需要在下一行输入,一个Case输入完成的标志是遇到换行符或者EOF。

然后在控制台中输入调试参数Case:

[2,7,11,15] 9
[3,2,4] 6
[3,3] 6

然后增强器会根据输入Case,运行Leetcode中的算法代码,并输出算法结果到控制台:

[0,1]
[1,2]
[0,1]

📚 LeetcodeJavaDebugEnhancer功能详述

1、支持多样的输入源

API

public InputProvider getInputProvider();

描述

LeetcodeJavaDebugEnhancer提供了对控制台(ConsoleInputProvider)、文件/流(FileInputProvider)等多样输入源的支持。

LeetcodeJavaDebugEnhancer使用控制台作为默认的输入源。

如果你想要自定义输入源,请通过重写该方法返回一个有效的InputProvider

示例

假设现在有一个名为input.txt的文件,文件内容如下:

[2,7,11,15] 9
[3,2,4] 6
[3,3] 6

下面是一个把input.txt文件作为输入源的示例代码:

//SimpleTest.java

import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
import io.github.jidcoo.opto.lcdb.enhancer.base.InputProvider;
import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.FileInputProvider;

import java.io.FileNotFoundException;

public class SimpleTest extends LeetcodeJavaDebugEnhancer {

    class Solution {
        public int[] twoSum(int[] nums, int target) {
            int n = nums.length;
            for (int i = 0; i < n; ++i) {
                for (int j = i + 1; j < n; ++j) {
                    if (nums[i] + nums[j] == target) {
                        return new int[]{i, j};
                    }
                }
            }
            return new int[0];
        }
    }

    @Override
    public InputProvider getInputProvider() {
        try {
            // FileInputProvider can accept file-name, file-object, and input-stream as construction parameters.
            return new FileInputProvider("input.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

}

2、支持多样的输出源

API

public OutputConsumer getOutputConsumer();

描述

LeetcodeJavaDebugEnhancer提供了对控制台(ConsoleOutputConsumer)、文件/流(FileOutputConsumer)等多样输入源的支持。

LeetcodeJavaDebugEnhancer使用控制台作为默认的输出源。

如果你想要自定义输出源,请通过重写该方法返回一个有效的OutputConsumer

示例

接着上面的示例,下面是一个把input.txt文件作为输入源,output.txt文件作为输出源的示例代码:

//SimpleTest.java

import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
import io.github.jidcoo.opto.lcdb.enhancer.base.InputProvider;
import io.github.jidcoo.opto.lcdb.enhancer.base.OutputConsumer;
import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.FileInputProvider;
import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.FileOutputConsumer;

import java.io.FileNotFoundException;

public class SimpleTest extends LeetcodeJavaDebugEnhancer {

    class Solution {
        public int[] twoSum(int[] nums, int target) {
            int n = nums.length;
            for (int i = 0; i < n; ++i) {
                for (int j = i + 1; j < n; ++j) {
                    if (nums[i] + nums[j] == target) {
                        return new int[]{i, j};
                    }
                }
            }
            return new int[0];
        }
    }

    @Override
    public InputProvider getInputProvider() {
        try {
            // FileInputProvider can accept file-name, file-object, and input-stream as construction parameters.
            return new FileInputProvider("input.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public OutputConsumer getOutputConsumer() {
        try {
            // FileOutputConsumer can accept file-name, file-object, and ouput-stream as construction parameters.
            return new FileOutputConsumer("output.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

}

3、支持自定义调试增强入口点

API

public Method getEnhancementPoint();

描述

众所周知,在Leetcode上有一些算法题目为数据结构设计题,例如最小栈用队列实现栈等。

上述这类题目对目前的调试增强器并不友好,因为这类题目并没有一个特别明确的算法入口,调试增强器很难找到一个有效的增强切入点。

因此针对这类题目的调试,请 尽最大可能地 通过重写该方法为调试增强器提供一个来自当前public类的(例如上面示例中的SimpleTest)、有效的、明确的增强切入点Method,调试增强器将会从该增强点切入执行调试增强逻辑,从而实现代码调试的目的。

示例

假设现在有一个名为input.txt的文件,文件内容如下:

["MyStack","push","push","top","pop","empty"] [[],[1],[2],[],[],[]]

下面是一个把input.txt文件作为输入源,并自定义实现增强点 runHere(String[] operations, int[][] numbers) 方法进行调试的示例代码:

//SimpleTest.java

import io.github.jidcoo.opto.lcdb.enhancer.LeetcodeJavaDebugEnhancer;
import io.github.jidcoo.opto.lcdb.enhancer.base.InputProvider;
import io.github.jidcoo.opto.lcdb.enhancer.core.io.builtin.FileInputProvider;
import io.github.jidcoo.opto.lcdb.enhancer.utils.ReflectUtil;

import java.io.FileNotFoundException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class SimpleTest extends LeetcodeJavaDebugEnhancer {

    class MyStack {
        Queue<Integer> queue1;
        Queue<Integer> queue2;

        /**
         * Initialize your data structure here.
         */
        public MyStack() {
            queue1 = new LinkedList<Integer>();
            queue2 = new LinkedList<Integer>();
        }

        /**
         * Push element x onto stack.
         */
        public void push(int x) {
            queue2.offer(x);
            while (!queue1.isEmpty()) {
                queue2.offer(queue1.poll());
            }
            Queue<Integer> temp = queue1;
            queue1 = queue2;
            queue2 = temp;
        }

        /**
         * Removes the element on top of the stack and returns that element.
         */
        public int pop() {
            return queue1.poll();
        }

        /**
         * Get the top element.
         */
        public int top() {
            return queue1.peek();
        }

        /**
         * Returns whether the stack is empty.
         */
        public boolean empty() {
            return queue1.isEmpty();
        }
    }

    /**
     * Enhancement point function.
     *
     * @param operations
     * @param numbers
     * @return
     */
    public List<Object> runHere(String[] operations, int[][] numbers) {
        List<Object> ans = new ArrayList<>();
        MyStack stack = null;
        for (int i = 0; i < operations.length; i++) {
            String operation = operations[i];
            Object curReturn = null;
            switch (operation) {
                case "MyStack":
                    stack = new MyStack();
                    break;
                case "push":
                    stack.push(numbers[i][0]);
                    break;
                case "top":
                    curReturn = stack.top();
                    break;
                case "pop":
                    curReturn = stack.pop();
                    break;
                case "empty":
                    curReturn = stack.empty();
                    break;
            }
            ans.add(curReturn);
        }
        return ans;
    }

    @Override
    public Method getEnhancementPoint() {
        // Return the runHere() method object.
        // By the way, you can use ReflectUtil.getMethod() to easily obtain the specified enhancement point method of a class.
        return ReflectUtil.getMethod(SimpleTest.class, "runHere", String[].class, int[][].class);
    }

    @Override
    public InputProvider getInputProvider() {
        try {
            return new FileInputProvider("input.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

}

对于这种数据结构设计题目,public Method getEnhancementPoint()的设计思路是提供一种迂回但有用的方式让用户能够完成对此类题目的调试。

但不难发现的是,这样的设计可能会给用户增加额外的、意义不大的编码任务。

因此,在后续的版本迭代中,我们将尝试对这类数据结构设计题目场景进行抽象,把上述的“可能会给用户增加额外的、意义不大的编码任务”的过程交给调试增强器来自动完成!!!

请持续关注该项目,敬请期待 !!! 🎉 🎉 🎉

🐛 问题与反馈

关于问题

LeetcodeJavaDebugEnhancer使用GitHub的集成问题跟踪系统来记录缺陷和新特性功能请求。如果你想提出一个Issue,请遵循如下的推荐建议:

  • 在你提出Issue前,请先通过搜索Issue Tracker,看看是否已经有人报告了相关的Issue。
  • 如果没有相关的Issue记录,请创建一个新的issue
  • 在Issue报告中提供尽可能多的信息,让我能够快速了解你当前使用的如调试增强器版本、Java版本、Leetcode题目、输入、输出、异常堆栈输出等信息。
  • 如果你需要粘贴代码或者包含堆栈信息的文本,请在相应文本前和文本后使用Markdown的代码块```进行转义。
  • 如果可以的话,请给出一个能够复现问题的测试Case,并将其附加到Issue上。

关于反馈

有关LeetcodeJavaDebugEnhancer的任何反馈、建议或者新特性功能请求,可以通过提出Issue的方式向我反馈。

当然,你也可以直接通过邮件的方式联系我:

昵称: Jidcoo

邮箱: jidcoo@163.com

🎉 贡献

欢迎任何人对此项目的任何形式的贡献!!!无论是新特性功能请求、Issue报告、代码提交、文档或其他类型的贡献或支持!!!

开源的快乐不就来自于此吗?!!!

所有提交的内容都需要经过代码审查,所以我们使用Github的pull requests。有关PullRequest的使用,你可以查阅Github的帮助文档

📜 许可证

LeetcodeJavaDebugEnhancer是基于Apache 2.0 license发布的开源项目。

Copyright 2024-2026 Jidcoo(https://github.com/jidcoo).

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

LeetcodeJavaDebugEnhancer是一个用于Java的Leetcode算法题的本地调试增强器 :rocket: :dart: 目标 提供方便快速的调试功能 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/mirrors/LeetcodeJavaDebugEnhancer.git
git@gitee.com:mirrors/LeetcodeJavaDebugEnhancer.git
mirrors
LeetcodeJavaDebugEnhancer
LeetcodeJavaDebugEnhancer
main

搜索帮助