输入:cardPoints=[1,1000,1],k=1输出:1解释:你无法拿到中间那张卡牌,所以可以获得的最大点数为1。 示例5: 输入:cardPoints = [1,79,80,1,1,1,200,1], k = 3 输出:202 提示: 1 <= cardPoints.length <= 10^5 1 <= cardPoints[i] <= 10^4 1 <= k <= cardPoints.length 解题思路 递...
Given the integer array cardPoints and the integer k, return the maximum score you can obtain. Example 1: Input: cardPoints = [1,2,3,4,5,6,1], k = 3 Output: 12 Explanation: After the first step, your score will always be 1. However, choosing the rightmost card first will maximiz...
There are several cards arranged in a row, and each card has an associated number of points The points are given in the integer arraycardPoints. In one step, you can take one card from the beginning or from the end of the row. You have to take exactlykcards. Your score is the sum ...
Ref:https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/ 这道题利用滑动窗口可解,设一长度为 的滑动窗口,以步长为1在 上滑动,剩余元素之和则为带求 张卡牌之和,主要代码如下: classSolution:defmaxScore(self,cardPoints:List[int],k:int)->int:n=len(cardPoints)total_sum=sum...
https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/ 几张卡牌 排成一行,每张卡牌都有一个对应的点数。点数由整数数组 cardPoints 给出。 每次行动,你可以从行的开头或者末尾拿一张卡牌,最终你必须正好拿 k 张卡牌。 你的点数就是你拿到手中的所有卡牌的点数之和。
In one step, you can take one card from the beginning or from the end of the row. You have to take exactlykcards. Your score is the sum of the points of the cards you have taken. Given the integer arraycardPointsand the integerk, return themaximum scoreyou can obtain. ...
题目如下: Given a stringsof zeros and ones,return the maximum score after splitting the string into two non-empty substrings(i.e. left substring and right substring). The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right subs...
https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/ 给你一个由若干 0 和 1 组成的字符串 s ,请你计算并返回将该字符串分割成两个 非空 子字符串(即左 子字符串和 右 子字符串)所能获得的最大得分。 「分割字符串的得分」为左 子字符串中 0 的数量加上 右 子字符串中 1...
Maximum Points You Can Obtain from Cards (M) 题目 There are several cardsarranged in a row, and each card has an associated number of points The points are given in the integer arraycardPoints. In one step, you can take one card from the beginning or from the end of the row. You ha...
题目如下: Given a stringsof zeros and ones,return the maximum score after splitting the string into two non-empty substrings(i.e. left substring and right substring). The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right subs...