当前位置:网站首页>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 把思路理清了,代码就顺理成章出来了
边栏推荐
猜你喜欢

Hyperparametric optimization (grid search and Bayesian Optimization)

Why did "you" become a test / development programmer? The value of your existence

Custom MVC principle and framework

编译原理研究性学习专题 2——递归下降语法分析设计原理与实现

MySQL log management, backup and recovery

Zabbix 5.0 使用自带Redis模版监控

Wechat applet development ④
![[self] - question brushing - peak value](/img/cf/9c47da9c574b61415578e7fde8b126.png)
[self] - question brushing - peak value

Optimization and implementation of custom MVC

类中多函数填写,LeetCode919——完全二叉树插入器
随机推荐
【自】-刷题-逻辑
零视科技 H5S视频平台 GetUserInfo 信息泄漏漏洞 CNVD-2020-67113
Runloop principle (I)
2022年R2移动式压力容器充装考题模拟考试平台操作
添加构建依赖项报错
机器学习问题笔记
金仓数据库 KingbaseES 与 Oracle 的兼容性说明(4. SQL)
LabVIEW对VISA Write和Read函数的异步和同步
浪潮ClusterEngineV4.0 远程命令执行漏洞 CVE-2020-21224
解决线程安全问题&&单例模式
[self] - brush questions logic
Read the recent trends of okaleido tiger and tap the value and potential behind it
Solve thread safety problems & singleton mode
Codeforces Round #474 (Div. 1 + Div. 2) - C, F
CV目标检测模型小抄(2)
Rhce第一天
新一代超安全蜂窝电池 思皓爱跑上市13.99万元起售
Wechat applet development ③
2022 R2 mobile pressure vessel filling test question simulation test platform operation
这款全网热评的无线路由器,到底有什么特别?