-
环和杆: https://leetcode.cn/problems/rings-and-rods/
-
统计范围内的元音字符串数: https://leetcode.cn/problems/count-the-number-of-vowel-strings-in-range/
-
最长平衡子字符串: https://leetcode.cn/problems/find-the-longest-balanced-substring-of-a-binary-string/
-
K 个元素的最大和: https://leetcode.cn/problems/maximum-sum-with-exactly-k-elements/
PriorityQueue优先取出最大值;文章来源:https://www.toymoban.com/news/detail-821865.html -
最长奇偶子数组: https://leetcode.cn/problems/longest-even-odd-subarray-with-threshold/
根据题意写代码,所有条件true不好判断,可以先把false的返回;文章来源地址https://www.toymoban.com/news/detail-821865.html
class Solution {
public int longestAlternatingSubarray(int[] nums, int threshold) {
int max = 0;
for (int i = 0; i < nums.length; i++) {
for (int r = i; r < nums.length; r++) {
if (isSatisfied(nums, threshold, i, r)) {
max = Math.max(r - i+1, max);
}
}
}
return max;
}
private static boolean isSatisfied(int[] nums, int threshold, int l, int r) {
if (nums[l] % 2 != 0) {
return false;
}
for (int i = l; i <= r; i++) {
if (nums[i] > threshold || (i < r && nums[i] % 2 == nums[i + 1])) {
return false;
}
}
return true;
}
}
到了这里,关于Java算法 leetcode简单刷题记录6的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!