idea 配置leetcode刷题插件并调试(白嫖debug)

配置参考

//这一行为CodeFileName内容
$!velocityTool.camelCaseName(${question.titleSlug})

//这一段为CodeTemplate内容,每次打开新题会自动生成main方法,代码块以内部类的形式存在
${question.content}
package leetcode.editor.cn;
public class $!velocityTool.camelCaseName(${question.titleSlug}){
    public static void main(String[] args) {
         Solution solution = new $!velocityTool.camelCaseName(${question.titleSlug})().new Solution();
         
    }
    ${question.code}
}

 debug示例:

 leetcode第一题,两数之和

/.../
package leetcode.editor.cn;

import java.util.HashMap;

public class TwoSum{
    public static void main(String[] args) {
         Solution solution = new TwoSum().new Solution();
         //以上部分自动生成,下一行用内部类的方式写输入即可调试
         solution.twoSum(new int[]{2,7,11,15}, 9);
    }

//leetcode只会提交BEGIN和END之间的代码,所以不需调试的时候无需写输入,代码可正常提交
    --BEGIN--
class Solution {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> hashtable = new HashMap<Integer, Integer>();
        for (int i = 0; i < nums.length; ++i) {
            if (hashtable.containsKey(target - nums[i])) {
                return new int[]{hashtable.get(target - nums[i]), i};
            }
            hashtable.put(nums[i], i); }
        return new int[0];
    }
}
--END--

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值