![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
贪心
江南路漫
这个作者很懒,什么都没留下…
展开
-
Leetcode贪心 K次取反后最大化的数组和
Given an integer array nums and an integer k, modify the array in the following way:choose an index i and replace nums[i] with -nums[i].You should apply this process exactly k times. You may choose the same index i multiple times.Return the largest poss原创 2021-08-24 21:53:34 · 68 阅读 · 0 评论 -
Leetcode贪心 摆动序列
A wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two原创 2021-08-23 09:26:08 · 70 阅读 · 0 评论 -
Leetcode贪心 验证回文字符串
Given a string s, return true if the s can be palindrome after deleting at most one character from it.思路用头尾指针遍历原字符串,但碰到所指不相同时,需要退出循环记录此书指针的位置。分别去除两个指针上的内容,查看删除一个字符后的字符串是否为回文串。代码class Solution {public: bool validPalindrome(string s) { int l原创 2021-08-22 13:14:33 · 72 阅读 · 0 评论 -
Leetcode贪心 种花问题
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.Given an integer array flowerbed containing 0’s and 1’s, where 0 means empty and 1 means not empty, and an integer n,原创 2021-08-22 09:01:40 · 84 阅读 · 0 评论 -
Leetcode贪心 分发饼干
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cook原创 2021-08-20 08:52:57 · 74 阅读 · 0 评论 -
LeetCode贪心 加油站
There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey原创 2021-08-16 16:54:12 · 57 阅读 · 0 评论 -
LeetCode贪心 最长回文串
Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.Letters are case sensitive, for example, “Aa” is not considered a palindrome here.思路首先学习一个新单词,palindrome回原创 2021-08-05 15:01:07 · 262 阅读 · 0 评论 -
LeetCode贪心 数组拆分I
Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), …, (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.思路这道题要使得各最小值相加最小,就要使得的每一组中的两数差的绝对值最小。假如一对数字中的差很大,会导致这对数字中较大的数字原创 2021-08-05 14:24:22 · 111 阅读 · 0 评论