摘要:
思路:排序 + 贪心算法 每次拿最大的饼干与最贪心的小朋友进行比较,如果满足,则可以让其满足;否则,继续找下一个小朋友。 由于贪心算法通常每一次操作都需要取最大值或最小值,因此需要对数组排序。 class Solution { public int findContentChildren(int[] 阅读全文
摘要:
☆☆☆☆思路:哈希表。参考 官方题解 class Solution { public int longestConsecutive(int[] nums) { Set<Integer> set = new HashSet<>(); for (int num : nums) { set.add(num 阅读全文
摘要:
class Solution { public int findLengthOfLCIS(int[] nums) { if (nums == null || nums.length == 0) return 0; int res = 1; int len = 1; for (int i = 1; i 阅读全文