#1423. Maximum Points You Can Obtain from Cards

IKM 测试题 - Java SE 8 评估测试题目 阅读详情

题目描述:

There are several cards arranged in a row, and each card has an associated number of points The points are given in the integer array cardPoints.

In one step, you can take one card from the beginning or from the end of the row. You have to take exactly k cards.

Your score is the sum of the points of the cards you have taken.

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 maximize your total score. The optimal strategy is to take the three cards on the right, giving a final score of 1 + 6 + 5 = 12.

Example 2:

Input: cardPoints = [2,2,2], k = 2
Output: 4
Explanation: Regardless of which two cards you take, your score will always be 4.

Example 3:

Input: cardPoints = [9,7,7,9,7,7,9], k = 7
Output: 55
Explanation: You have to take all the cards. Your score is the sum of points of all cards.

Example 4:

Input: cardPoints = [1,1000,1], k = 1
Output: 1
Explanation: You cannot take the card in the middle. Your best score is 1. 

Example 5:

Input: cardPoints = [1,79,80,1,1,1,200,1], k = 3
Output: 202

Constraints:

  • 1 <= cardPoints.length <= 10^5
  • 1 <= cardPoints[i] <= 10^4
  • 1 <= k <= cardPoints.length
class Solution {
public:
    int maxScore(vector<int>& cardPoints, int k) {
        int n = cardPoints.size();
        // 空出首尾的前后缀之和更简便
        vector<int> prefix_sum(n + 1, 0);
        vector<int> surfix_sum(n + 1, 0);
        for (int i = 1; i < n; i++) {
            prefix_sum[i] = prefix_sum[i - 1] + cardPoints[i - 1];
        }
        for (int i = n - 1; i >= 0; i--) {
            surfix_sum[i] = surfix_sum[i + 1] + cardPoints[i];
        }
        int max_sum = 0;
        for (int i = 0; i <= k; i++) {
            max_sum = max(max_sum, prefix_sum[i] + surfix_sum[n + i - k]);
        }
        return max_sum;
    }
};

 

【异常】Antigravity IDE 登录异常与网络连接错误排查指南 在使用 Google 推出的 AI 原生 IDE时,部分用户可能会遇到身份验证失效与网络环境冲突导致的叠加错误。本文将针对此类典型故障提供完整的解决思路。 阅读详情

相关推荐

DCN交换机通过boot模式升级

LIC导入成功后,输入enable进入特权模式,把网线接到通讯网口上,配置好对应interface vlan地址,在enable模式用 copy tftp://x.x.x.x/xxxxxx_nos.img nos.img待提示write ok时,reload设备完成升级。交换机启动后,在显示以下信息时输入“Ctrl+B”,一定得是手动按“Ctrl+B”进入的boot模式才能正常升级。升级交换机成功,在BootROM模式下,执行命令run或reboot,回到CLI配置界面。# 交换机通过boot模式升级。

m0_72501865的博客 946

每日一题 21.02.06 LeetCode 1423. 可获得的最大点数题解

题目 https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/ 分析 等价于 寻找一个元素和最小的滑动窗口(窗口内有连续len-k个元素)。窗口两侧外侧的数之和就是我们要求的数之和。因为要求最大,所以求窗口和最小。 代码 class Solution { public int maxScore(int[] cardPoints, int k) { int len=cardPoints.len

乾坤未定,你我皆是黑马 255

Twin Builder CFD 示例:构建、验证和评估静态 ROM

通过我们构建、验证和评估静态 ROM 的综合指南,释放 Twin Builder CFD 的潜力。

jkh920184196的博客 1100

LeetCode 1423 Maximum Points You Can Obtain from Cards (前缀和)

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 have to take exactlyk...

Tc的专栏 396

欧姆龙PLC与fanuc发那科机器人进行Ethrenet ip通信测试

近期在做发那科FANUC的通讯,会吧CC-LINK、Profibus-DP、Profinet I/O、DeviceNet、EtherNet/IP这些常用通讯做成文档发上来,大家喜欢的话可以关注 注:做对应的通讯,在机器人控制柜都需要安装对应的板卡以及软件功能 截图中的程序设置和机器人EDS插件在下面链接 https://download.csdn.net/download/gojava/13770799 PLC为主站 机器人为从站 一、硬件部分 欧姆龙PLC ...

七兔自习室 1万+

WRF后处理避坑指南:从namelist配置到降水计算的全流程解析

本文提供了一份详尽的WRF模式后处理避坑指南,涵盖从理解wrfout文件结构、核心变量解析到累计降水计算与专业气象图绘制的全流程。重点解析了RAINC与RAINNC的正确处理方法,并分享了使用wrf-python库高效绘制位势高度叠加风场图、累计降水图等专业图表的实战技巧与代码,旨在帮助用户规避常见错误,提升后处理效率与图表质量。

weixin_29200485的博客 353

Leetcode 1423. Maximum Points You Can Obtain from Cards (python)

题目 解法1:O(n) 利用prefix sum,遍历k种不同组合 class Solution: def maxScore(self, cardPoints: List[int], k: int) -> int: prefix_sum = [0] tmp = 0 for card in cardPoints: tmp += card prefix_sum.append(tmp)

qq_37821701的博客 361

2021年软件测试面试题大全

简述测试流程: 1、阅读相关技术文档(如产品PRD、UI设计、产品流程图等)。 2、参加需求评审会议。 3、根据最终确定的需求文档编写测试计划。 4、编写测试用例(等价类划分法、边界值分析法等)。 5、用例评审(主要参与人员:开发、测试、产品、测试leader)。 6、开发提交代码至SVN或者GIT ,配管搭建测试环境。 7、执行测试用例,记录发现的问题。 8、验证bug与回归测试。 9、编写测试报告。 10、产品上线。 补充测试用例设计过程: 根据需求得出测试需求 设计测试方

hard_days的博客 20万+

Maximum Points You Can Obtain from Cards

There are several cardsarranged in a row, and each card has an associated number of pointsThe 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 exactlyk...

leetcode 解题思路 612

数据挖掘实战-基于长短期记忆网络(LSTM)的黄金价格预测模型 | 97% 准确度

本实验基于Kaggle上提供的从2013年到2023年的黄金价格数据集,运用长短期记忆网络(LSTM)构建了黄金价格预测模型。该数据集详细记录了每日的黄金价格信息,包括开盘价、收盘价、高点、低点和交易量等,为模型的训练提供了丰富的数据支持。

m0_64336780的博客 1万+

仿真学习系列(四十二):Sigrity仿真之走线阻抗和耦合检查

在高速电路设计中,走线的阻抗和信号线之间的耦合是影响信号完整性的重要因素。设计中可能会出现多种情况,导致阻抗变化或不匹配,例如线宽的变化、跨层分割等。传统的人工检查方法常常不够高效且易忽视细节。借助仿真软件,可以快速定位问题区域,并进行精确分析,从而有效避免或减少信号反射和串扰带来的影响。

案例文章,高速信号 423

Leetcode 1423:可获得最大的点数

题目描述 几张卡牌 排成一行,每张卡牌都有一个对应的点数。点数由整数数组 cardPoints 给出。 每次行动,你可以从行的开头或者末尾拿一张卡牌,最终你必须正好拿 k 张卡牌。 你的点数就是你拿到手中的所有卡牌的点数之和。 给你一个整数数组 cardPoints 和整数 k,请你返回可以获得的最大点数。 示例 1: 输入:cardPoints = [1,2,3,4,5,6,1...

weixin_35338624的博客 349

【模型实战】MiMo-VL-7B讲解与实战

维度成绩MMMU70.6(图像理解最难测试之一)VideoMME70.8(视频理解标杆)59.4(超越78B参数模型)56.1(超过专用GUI模型)Elo评分开源VLM排名第一(7B~72B)社区热度过去一个月下载超1,600次(RL+SFT)📌一句话概括MiMo-VL 是目前性能最强、推理最稳、体验最佳、生态最全的7B级开源视觉语言模型。

m0_47867638的博客 1194

1423. Maximum Points You Can Obtain from Cards(Leetcode每日一题-2021.02.06)

Problem There are several cards arranged in a row, and each card has an associated number of points The points are given in the integer array cardPoints. In one step, you can take one card from the beginning or from the end of the row. You have to take exa

Bryan要加油 522

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

leetcode第186场周赛

目录 第一题、分割字符串的最大得分 第二题、可获得的最大点数 第三题、对角线遍历 第四题、带限制的子序列和 leetcode第186场周赛,时间2020/04/26 10:30-12:00 第一题、分割字符串的最大得分 难度:easy,链接:https://leetcode-cn.com/problems/maximum-score-after-splitting-a-stri...

wuqindeyunque的博客 338

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

1423 可获得的最大点数(滑动窗口)

1. 问题描述: 几张卡牌 排成一行,每张卡牌都有一个对应的点数。点数由整数数组 cardPoints 给出。 每次行动,你可以从行的开头或者末尾拿一张卡牌,最终你必须正好拿 k 张卡牌。 你的点数就是你拿到手中的所有卡牌的点数之和。 给你一个整数数组 cardPoints 和整数 k,请你返回可以获得的最大点数。 示例 1: 输入:cardPoints = [1,2,3,4,5,6,1], k = 3 输出:12 解释:第一次行动,不管拿哪张牌,你的点数总是 1 。但是,先拿最右边的卡牌将会最

二哈 383

【LeetCode】1423. 可获得的最大点数 Maximum Points You Can Obtain from Cards (Python)

作者: 负雪明烛 id: fuxuemingzhu 公众号:每日算法题 本文关键词:LeetCode,力扣,算法,算法题,滑动窗口,递归,前缀和,preSum,刷题群 目录题目描述解题思路递归preSum滑动窗口刷题心得欢迎加入组织日期 题目地址:https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/ 题目描述 几张卡牌 排成一行,每张卡牌都有一个对应的点数。点数由整数数组 cardPoint.

负雪明烛 1986

Leetcode——5393. 可获得的最大点数

5393. 可获得的最大点数 几张卡牌 排成一行,每张卡牌都有一个对应的点数。点数由整数数组 cardPoints 给出。 每次行动,你可以从行的开头或者末尾拿一张卡牌,最终你必须正好拿 k 张卡牌。 你的点数就是你拿到手中的所有卡牌的点数之和。 给你一个整数数组 cardPoints 和整数 k,请你返回可以获得的最大点数。 示例 1: 输入:cardPoints = [1,2,3,4,5,6,...

suxiaorui的博客 710

LeetCode第186场周赛(Weekly Contest 186)解题报告

今天周日,但是要补休,五一的。所以参赛人员少,而且题目也比较简单。 第一题:枚举。 第二题:滑动窗口 或者 前缀后缀和。 第三题:模拟。 第四题:贪心 或者 DP。 详细题解如下。 1.分割字符串的最大得分(Maximum Score after Splitting A String) AC代码(C++) 2.可获得的最大点数(Maximum Points Y...

Mikchy的博客 561

LeetCode 1423. 可获得的最大点数【定长滑窗,逆向和正向思维】1574

There are several cards arranged in a row, and each card has an associated number of points The points are given in the integer array cardPoints. In one step, you can take one card from the beginning or from the end of the row. You have to t

memcpy0的博客 473

[leetcode] 1423. Maximum Points You Can Obtain from Cards

Description There are several cards arranged in a row, and each card has an associated number of points The points are given in the integer array cardPoints. In one step, you can take one card from the beginning or from the end of the row. You have to take

Learning from the mistakes 354

证明精确的4SAT是NP_完全问题

题目描述: 在精确的4SAT(EXACT 4SAT)问题中,输入为一组子句,每个子句都是恰好4个文字的析取,且每个变量最多在每个子句中出现一次。目标是求它的满足赋值——如果该赋值存在。证明精确的4SAT是NP_完全问题。 显然,4SAT问题是NP问题,所有可能的赋值总数的指数级的。现从3SAT归约到4SAT来证明4SAT为NP_完全问题: 给定3SAT的实例,对I中的任意子句(a1∨

LawFile的博客 1685

LeetCode #22 - Generate Parentheses

题目描述: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()",

LawFile的博客 596

LeetCode #19 - Remove Nth Node From End of List

题目描述:   Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1-&gt;2-&gt;3-&gt;4-&gt;5, and n = 2. After removing the second n...

LawFile的博客 519

LeetCode #21 - Merge Two Sorted Lists

题目描述: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 此题可以直接模拟归并排序的步骤,但是要小心指针为空的情况。 /** * Defini

LawFile的博客 498

#1477. Find Two Non-overlapping Sub-arrays Each With Target Sum

题目描述: Given an array of integersarrand an integertarget. You have to findtwo non-overlapping sub-arraysofarreach with sum equaltarget. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays ...

LawFile的博客 462

LeetCode #25 - Reverse Nodes in k-Group

题目描述: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If t

LawFile的博客 438
上一篇: #752. Open the Lock
下一篇: #1477. Find Two Non-overlapping Sub-arrays Each With Target Sum
LawFile
博客等级 码龄10年 5粉丝 627原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值