Leetcode每日随机2021/5/2

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

leetcode1016
???在这里插入图片描述
这不就是调一下api?
leetcode1691
代码来自此题解
好像很麻烦的样子,不想看了,做不出来。
剑指offer48
双指针,找到所有满足要求的子串。复杂度2n。
这题和主站第三题一样,看了一眼以前的做法,真的暴力哈哈。

代码

leetcode1016

class Solution {
    public boolean queryString(String S, int N) {
		for (int i = 1; i <= N; i++) {
			if (S.indexOf(Integer.toBinaryString(i)) < 0) {
				return false;
			}
		}
		return true;
	}
}

leetcode1691

class Solution {
    public int maxHeight(int[][] cuboids) {
        for (int[] cuboid : cuboids) {
            Arrays.sort(cuboid);
        }
        Arrays.sort(cuboids, (o1, o2) -> {
            if (o1[0] != o2[0]) {
                return Integer.compare(o1[0], o2[0]);
            } else if (o1[1] != o2[1]) {
                return Integer.compare(o1[1], o2[1]);
            } else {
                return Integer.compare(o1[2], o2[2]);
            }
        });
        int[] dp = new int[cuboids.length];
        int maxAns = 0;
        for (int i = 0; i < cuboids.length; i++) {
            for (int j = 0; j < i; j++) {
                if (cuboids[j][1] <= cuboids[i][1] && cuboids[j][2] <= cuboids[i][2]) {
                    dp[i] = Math.max(dp[i], dp[j]);
                }
            }
            dp[i] += cuboids[i][2];
            maxAns = Math.max(maxAns, dp[i]);
        }
        return maxAns;
    }
}

剑指offer48

class Solution {
    public int lengthOfLongestSubstring(String s) {
		int start = -1, end = 0, max = 0;
		Map<Character, Integer> map = new HashMap<Character, Integer>();
		while (end < s.length()) {
			if (!map.containsKey(s.charAt(end))) {
				map.put(s.charAt(end), end);
				max = Math.max(max, end - start);
			} else {
				start = map.get(s.charAt(end));
				map.clear();
				for (int i = start + 1; i <= end; i++) {
					map.put(s.charAt(i), i);
				}
			}
			end++;
		}
		return max;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值