摘要:
可以读通讯稿的组数 这题一开始暴力来做,也就是二重循环,就超时了。 通过观察公式发现 镜像号码 A + 原号码 B = 镜像号码 B + 原号码 A 等价于 镜像号码 A - 原号码 A= 镜像号码 B - 原号码 B 这样只需要O(n)复杂度,结合哈希表就可以做出来了。 具体做法:计算每个数和它反 阅读全文
摘要:
记一个刷题过程中遇到的溢出问题。 在做这道题的时候遇到一个与 long 类型有关的溢出错误。 原始代码如下 class Solution { public int numberOfPairs(int[] nums) { long res = 0; int mod = (int)Math.pow(10 阅读全文
摘要:
二维 List 自定义排序 使用lambda表达式 import java.util.*; public class Main { public static void main(String[] args) { List<List<Integer>> list = new LinkedList<> 阅读全文
摘要:
Java遍历Map集合简单例子 import java.util.*; public class Main { public static void main(String[] args) { HashMap<Integer, Integer> map = new HashMap<>(); map. 阅读全文
摘要:
nSum问题模板 两数之和、三数之和、四数之和。 private List<List<Integer>> nSum(int[] nums, long target, int start, int n) { int len = nums.length; List<List<Integer>> res 阅读全文