IDEA使用LeetCode插件运行并调试本地样例

导读:本篇文章讲解 IDEA使用LeetCode插件运行并调试本地样例,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

环境: idea2020.1

插件: LeetCode-editor 6.7

一、IDEA安装LeetCode插件

在这里插入图片描述

安装完成重启idea

打开插件

在这里插入图片描述
在这里插入图片描述

URL可以选择国服和世界服。LoginName和Password填自己的用户名和密码即可。

需要配置的选项为:

TempFilePath: 自己保存代码的包的位置

CodeFileName:

$!velocityTool.camelCaseName(${question.titleSlug})

CodeTemplate:

${question.content}
package leetcode.editor.cn;
//Java:${question.title}
public class $!velocityTool.camelCaseName(${question.titleSlug}){
    public static void main(String[] args) {
        Solution solution = new $!velocityTool.camelCaseName(${question.titleSlug})().new Solution();
        // TO TEST
    }
    
    ${question.code}
}

配置完成后 刷新即可

输入代码测试运行提交

在这里插入图片描述
代码

package leetcode.editor.cn;

import java.util.Arrays;

//Java:两数之和
public class TwoSum {
    public static void main(String[] args) {
        Solution solution = new TwoSum().new Solution();
        // TO TEST
        int[] a ={1, 2, 3, 4};
        int[] ints = solution.twoSum(a, 3);
        System.out.println(Arrays.toString(ints));
    }
    class Solution {
        public int[] twoSum(int[] nums, int target) {
            for (int i = 0; i < nums.length; i++) {
                for (int j = i + 1; j < nums.length; j++) {
                    if (nums[j] == target - nums[i]) {
                        return new int[]{i, j};
                    }
                }
            }
            throw new IllegalArgumentException("No two sum solution");
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/77985.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!