注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 匿名 于 2021-8-25 18:04 编辑
Q1, 贼简单,不写了。
Q2, 给一个数字 int n, 再给一个长度 int k, 问:把 n 当成 String,然后所有的长度为 k 的 substring 中,有多少满足 n % Integer.parseInt(substring) == 0. 一定不要用 Integer.parseInt,会有一个 Hidden case过不了。要用这种形式,val * 10 + (ch - '0') - (int)(1ek)。我猜的,因为我有一个 case 没过(parseInt 方法)。
Q3, 其他面经里有,我这里只是简单描述下,两个 array,a 和 b,然后给一堆 query,[1两个都是0开始,放入set中,
第三个是1开始,判断2 * 2 的四边形是否被之前的任意一个四边形覆盖,被第二个覆盖,返回True,
第四个 3*4 没有被第一、第二个覆盖,返回False,虽然第五个是0且覆盖了第四个,但只考虑该序列之前的第一个数字是0的四边形.- public class 俄罗斯套娃 {
- public static void main(String[] args) {
- int[][] arr = {
- {0, 1, 1},
- {0, 2, 3},
- {1, 2, 2},
- {1, 3, 4},
- {0, 3, 4}
- };
- System.out.println (check (arr));
- }
- private static List<Boolean> check(int[][] arr) {
- TreeMap<Integer, Integer> treeMap = new TreeMap<> ();
- List<Boolean> result = new ArrayList<> ();
- for (int[] a : arr) {
- int height = Math.min (a[1], a[2]);
- int width = Math.max (a[1], a[2]);
- // 0, add
- if (a[0] == 0) {
- insert (treeMap, height, width);
- } else { // 1, check,
- Integer nextHeight = treeMap.ceilingKey (height);
- if (nextHeight == null) {
- result.add (false);
- } else {
- Integer nextWidth = treeMap.get (nextHeight);
- result.add (height <= nextHeight);
- }
- }
- }
- return result;
- }
- private static void insert(TreeMap<Integer, Integer> treeMap, int height, int width) {
- // lower key
- Integer lowerHeight = treeMap.lowerKey (height);
- while (lowerHeight != null && treeMap.get (lowerHeight).compareTo (width) <= 0) {
- treeMap.remove (lowerHeight);
- lowerHeight = treeMap.lowerKey (height);
- }
- // higher key
- Integer higherHeight = treeMap.higherKey (height);
- if (higherHeight != null && treeMap.get (higherHeight).compareTo (width) >= 0) {
- return;
- }
- treeMap.put (height, width);
- }
- }
复制代码 建议先做力扣彡灵灵和彡武肆。
应该是对的,哪里不对的话,欢迎探讨。另外,拒绝加米,我每天签到都四位数了。
|