当前位置:网站首页>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 把思路理清了,代码就顺理成章出来了
边栏推荐
- Runloop principle (I)
- 超参数优化(网格搜索和贝叶斯优化)
- 2022起重机械指挥考试题模拟考试平台操作
- Shenkaihong: on the river of Zhilian of all things, there is a bright moon of open source
- 宝塔 phpmyadmin未授权访问漏洞
- 搭载新一代超安全蜂窝电池,思皓爱跑上市13.99万元起售
- 剑指 Offer 41. 数据流中的中位数
- 2022g3 boiler water treatment test simulation 100 questions simulation test platform operation
- [self] - question brushing - dynamic programming
- 【自】-刷题-BFS
猜你喜欢

剑指 Offer 41. 数据流中的中位数

field injection is not recommended 的解决办法

机器学习问题笔记

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

如何开一家盈利的健身房?我用1年回本的经验告诉你,别谈恋爱

金仓数据库KingbaseES 客户端编程接口指南 - ODBC (2. 概述)

Codeforces Round #810 (Div. 2) A - C

【自】-刷题-动态规划

mongodb索引添加、查看、导出、删除

Few people can really play in the "aftermarket" of the whole house intelligent fire collection
随机推荐
CV实例分割模型小抄(1)
Compatibility description between kingbasees and Oracle (3. Common functions)
Byte 8 years' experience of female test Director - for girls who want to change careers or are about to enter the testing industry
CV语义分割模型小抄(2)
Zabbix 5.0 使用自带Redis模版监控
Runloop principle (I)
Function function
In depth analysis of integrated learning xgboost (Continued)
剑指 Offer 55 - I. 二叉树的深度
Manufacturing steps of interactive slide screen in exhibition hall
[self] - brush questions logic
Zero view h5s video platform getUserInfo information disclosure vulnerability cnvd-2020-67113
深度剖析集成学习Adaboost
互动滑轨屏在展厅中应用的制作步骤
2022 G2 power plant boiler stoker examination question bank simulated examination platform operation
如何开一家盈利的健身房?我用1年回本的经验告诉你,别谈恋爱
Samba service setup
NPDP考试需要携带什么?文具携带说明
2022t elevator repair examination questions and simulation examination
npm更换最新淘宝镜像