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

代码随想录——划分字母区间(Leetcode763)

题目链接
在这里插入图片描述

贪心

class Solution {public List<Integer> partitionLabels(String s) {int[] count = new int[27];Arrays.fill(count,0);// 统计元素最后一次出现的位置for(int i = 0; i < s.length(); i++){count[s.charAt(i) - 'a'] = i;}List<Integer> res = new ArrayList<Integer>();int left = 0;int right = 0;for(int i = 0; i < s.length(); i++){// 找到字符出现的最远边界right = Math.max(right, count[s.charAt(i) - 'a']);if(i == right){// 将符合条件的字符串长度插入resres.add(right - left + 1);left = i + 1;}}return res;}
}
http://www.lryc.cn/news/393313.html

相关文章:

  • SQL注入方法
  • Vue表单输入绑定v-model
  • 【分布式系统】ELK 企业级日志分析系统
  • vs2019 无法打开项目文件
  • Elasticsearch:Painless scripting 语言(一)
  • SpringBoot项目练习
  • Android Gradle 开发与应用 (七): Gradle 插件开发与发布
  • 方法引用详解
  • Apache Seata 高可用部署实践
  • nginx配置尝试
  • SAR目标检测
  • 创新配置,秒级采集,火爆短视频评论抓取
  • STL—容器—string类【对其结构和使用的了解】【对oj相关练习的训练】
  • 讲个SystemVerilog随机约束小坑
  • mysql在windows下的安装
  • uniapp 在手机上导出excel
  • 收银系统源码-收银台副屏广告
  • 【TORCH】torch.normal()中的size参数
  • 【第20章】MyBatis-Plus逻辑删除支持
  • 【IT领域新生必看】 Java编程中的重载(Overloading):初学者轻松掌握的全方位指南
  • python转文本为语音并播放
  • 解锁高效软件测试:虚拟机助力提升测试流程的秘诀
  • 创建vue3项目
  • 中国网络安全审查认证和市场监管大数据中心数据合规官CCRC-DCO
  • Web漏洞扫描工具AppScan与AWVS测评及使用体验
  • 瞰景Smart3D使用体验分享
  • Android系统adb shell dumpsys activity processes
  • vue侦听器watch()
  • 如何用Python向PPT中批量插入图片
  • C# Socket