当前位置:网站首页>leetcode 763. Partition Labels 划分字母区间(中等)
leetcode 763. Partition Labels 划分字母区间(中等)
2022-07-28 21:55:00 【InfoQ】
一、题目大意
- S的长度在[1, 500]之间。
- S只包含小写字母 'a' 到 'z' 。
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public List<Integer> partitionLabels(String s) {
Map<Character, Integer> map = new HashMap<>();
char[] cArr = s.toCharArray();
for (int i = 0; i < cArr.length; i++) {
map.put(cArr[i], i);
}
List<Integer> res = new ArrayList<>();
int start = 0;
int last = 0;
for (int i = 0; i < cArr.length; i++) {
last = Math.max(map.get(cArr[i]), last);
if (i == last) {
res.add(last - start + 1);
start = last + 1;
}
}
return res;
}
}
四、总结小记
- 2022/7/28 把思路理清了,代码就顺理成章出来了
边栏推荐
- Zabbix 5.0 使用自带Redis模版监控
- Intel data center GPU is officially shipped to provide strong computing power with openness and flexibility
- field injection is not recommended 的解决办法
- Objc4-841.13 debuggable / compiled source code update
- 金仓数据库KingbaseES客户端编程接口指南-ODBC(5. 开发过程)
- Typescript prevents base classes from being instantiated
- 金仓数据库 KingbaseES 与 Oracle 的兼容性说明(4. SQL)
- Inspur clusterenginev4.0 remote command execution vulnerability cve-2020-21224
- 深度之眼(十八)——偏导数
- KingbaseES客户端编程接口指南-ODBC(4. 创建数据源)
猜你喜欢

2022年G2电站锅炉司炉考试题库模拟考试平台操作

Achieve high throughput through Wi Fi 7 - insight into the next generation of Wi Fi physical layer

2022 welder (Junior) work license questions and answers

Intel data center GPU is officially shipped to provide strong computing power with openness and flexibility

智能垃圾桶(七)——SG90舵机的介绍与使用(树莓派pico实现)

电脑不知卸载什么,打不开计算器无法编辑截图功能打不开txt文件等等解决方案之一
![[self] - question brushing - string](/img/80/7d571e4f82caaad00d0a20152832c2.png)
[self] - question brushing - string

Development of small programs ①

阻塞式队列

剑指 Offer 41. 数据流中的中位数
随机推荐
Wechat applet development ④
Manufacturing steps of interactive slide screen in exhibition hall
Compatibility description between kingbasees and Oracle (3. Common functions)
2022年R2移动式压力容器充装考题模拟考试平台操作
XML modeling
CV语义分割模型小抄(2)
你学过的每样东西,都会在你一生中的某个时刻派上用场(转)
毕业三年之际写给可能迷茫的你我[转]
事件抽取文献整理(2008-2017)
Compatibility description between kingbasees and Oracle (2. Data type)
AUTOCAD——Excel表格导入CAD、CAD合并两兄弟
(22) two permutation (DP), package delivery (greedy)
2022T电梯修理考试试题及模拟考试
MySQL introduction
Shenkaihong: on the river of Zhilian of all things, there is a bright moon of open source
Intel data center GPU is officially shipped to provide strong computing power with openness and flexibility
CV目标检测模型小抄(2)
Pin mapping relationship of stm32f103c series single chip microcomputer under Arduino framework
22 Niuke multi school Day1 I - Introduction to chiitoitsu DP
编译原理研究性学习专题 2——递归下降语法分析设计原理与实现