3.30/1606找到请求最多的处理器
太难了,我是废物
3.31/自除数,即数本身能被各位上的元素整除
class Solution {public List<Integer> selfDividingNumbers(int left, int right) {List<Integer> ans = new ArrayList<Integer>();for (int i = left; i <= right; i++) {if (isSelfDividing(i)) {ans.add(i);}}return ans;}public boolean isSelfDividing(int num) {int temp = num;while (temp > 0) {int digit = temp % 10;if (digit == 0 || num % digit != 0) {return false;}temp /= 10;}return true;}}
4.1二倍数数组
数组能不能拆成奇数位置是偶数位置二倍的样子
class Solution {
public boolean canReorderDoubled(int[] arr) {
Map<Integer, Integer> cnt = new HashMap<Integer, Integer>();
for (int x : arr) {
cnt.put(x, cnt.getOrDefault(x, 0) + 1);
}
if (cnt.getOrDefault(0, 0) % 2 != 0) {
return false;
}
List<Integer> vals = new ArrayList<Integer>();
for (int x : cnt.keySet()) {
vals.add(x);
}
Collections.sort(vals, (a, b) -> Math.abs(a) - Math.abs(b));
for (int x : vals) {
if (cnt.getOrDefault(2 * x, 0) < cnt.get(x)) { // 无法找到足够的 2x 与 x 配对
return false;
}
cnt.put(2 * x, cnt.getOrDefault(2 * x, 0) - cnt.get(x));
}
return true;
}
}
