题
思
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;
}
}