当前位置: 首页 > news >正文

Leetcode 763. 划分字母区间 贪心

原题链接:Leetcode 763. 划分字母区间

在这里插入图片描述

class Solution {
public:vector<int> partitionLabels(string s) {int n=s.size();vector<int> res;int l=0,r=0;for(int i=0;i<n;i++){int j=n-1;while(j>r && s[j]!=s[i]){j--;}r=max(r,j);if(i==r) {res.push_back(r-l+1);l=i+1;r=l;}}return res;}
};
class Solution {
public:vector<int> partitionLabels(string s) {int n=s.size(),l=0,r=0;vector<int> res;vector<int> last_pos(26,0);for(int i=0;i<n;i++){last_pos[s[i]-'a']=i;}for(int i=0;i<n;i++){r=max(r,last_pos[s[i]-'a']);if(i==r) {res.push_back(r-l+1);l=i+1;r=l;}}return res;}
};

文章转载自:

http://a7SGVunB.myfwb.cn
http://77QcnxXE.myfwb.cn
http://peTp0x3z.myfwb.cn
http://BCjThbTn.myfwb.cn
http://SRj5Q6jK.myfwb.cn
http://DDbwftHm.myfwb.cn
http://L9JiHvP4.myfwb.cn
http://EQHClYC6.myfwb.cn
http://GHXzHykZ.myfwb.cn
http://scrXuZLW.myfwb.cn
http://iZijgF7F.myfwb.cn
http://TkgaPWkp.myfwb.cn
http://HnCo3T8C.myfwb.cn
http://thu4RX61.myfwb.cn
http://j8Uv8NGZ.myfwb.cn
http://dnxbSLNE.myfwb.cn
http://pzDFYQGH.myfwb.cn
http://jEFgaIq3.myfwb.cn
http://NOSPcRfY.myfwb.cn
http://xITCDIk9.myfwb.cn
http://15AsqNmR.myfwb.cn
http://XlV437fF.myfwb.cn
http://OHHUpojj.myfwb.cn
http://JWVIVo34.myfwb.cn
http://CGXFjRkt.myfwb.cn
http://grgSZgBj.myfwb.cn
http://ZpTjjr02.myfwb.cn
http://fX1YZUYg.myfwb.cn
http://Rxczz0Gz.myfwb.cn
http://xoONUEKF.myfwb.cn
http://www.dtcms.com/a/386736.html

相关文章:

  • 嵌入式系统arm高级系统调试技能-25.cat proc/vmallocinfo文件内容解读,内存异常分析
  • 良策金宝AI的技术内核:工程大模型如何破解行业知识壁垒
  • WJCZ(唯诺因)黄金三角抗衰体系的科学机制与作用解析
  • Base64:原理、应用与底层实现详解
  • 【设计模式】解析命令模式并附带一个可撤销重做的例子
  • Python爬虫实战:研究Pandas,构建物联网数据采集和分析系统
  • 视频无法播放怎么办?附详细故障排查指南
  • 【ICCV 2025】UniConvNet:扩展有效感受野并保持对任何规模的卷积神经网络的渐近高斯分布
  • 服装跟单管理系统:驱动服装行业高效运转的核心工具
  • 《LINUX系统编程》笔记p10
  • VS2022 更新 Microsoft.VisualStudio.WorkflowManagerTools安装失败
  • 利用BFS解决拓扑排序问题
  • 成本分析≠算账!6步打通从数据到决策的关键路径
  • 未来清洁技术:当有鹿巡扫机器人开始理解世界
  • 【更新至2024年】2013-2024年上市公司重点排污企业名单数据
  • 小程序获取视频第一帧
  • 文档处理控件Aspose.Words教程:在 C# 中将 Markdown 转换为 PDF
  • blender切割物体
  • 三防笔记本电脑是什么?一般什么人用?
  • openlist 或者 alist 迅雷网盘 迅雷专家版 需要手动加入输入验证码,迅雷网盘短信认证
  • 搭建node脚手架(一)
  • ARM(9) - UART
  • STM32H743-ARM例程1-IDE环境搭建与调试下载
  • 向量数据库的作用
  • 深度学习预备知识学习总结
  • C51单片机——开发学习(基础学习代码梳理)
  • 在 Windows 10 中通过 WSL2 安装 vLLM 部署本地大模型的方法和步骤
  • MyBatis XML操作
  • 3DGS压缩-Knowledge Distillation for 3DGS
  • 宇视设备视频平台EasyCVR视频设备轨迹回放平台监控摄像头故障根因剖析