当前位置:网站首页>Leetcode 763. partition labels divide alphabetic intervals (medium)
Leetcode 763. partition labels divide alphabetic intervals (medium)
2022-07-28 23:53:00 【InfoQ】
One 、 The main idea of the topic
- S The length of is [1, 500] Between .
- S Contains only lowercase letters 'a' To 'z' .
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
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;
}
}
Four 、 Summary notes
- 2022/7/28 Clear your mind , The code comes out naturally
边栏推荐
- Arduino uno driver universe 1.8 'TFT SPI screen example demonstration (including data package)
- Codeforces Round #810 (Div. 2) A - C
- 毕业三年之际写给可能迷茫的你我[转]
- 【自】-刷题-数组
- 2022g3 boiler water treatment test simulation 100 questions simulation test platform operation
- Asynchronism and synchronization of visa write and read functions by LabVIEW
- Deep analysis of integrated learning AdaBoost
- Deep analysis of integrated learning xgboost
- OpenCV宏定义
- 剑指 Offer 55 - I. 二叉树的深度
猜你喜欢

通配符 SSL/TLS 证书

Arduino uno driver universe 1.8 'TFT SPI screen example demonstration (including data package)

Class, leetcode919 -- complete binary tree inserter

field injection is not recommended 的解决办法

【自】-刷题-字符串

A new generation of ultra safe cellular battery, Sihao aipao, will be available from 139900 yuan
![[self] - question brushing - peak value](/img/cf/9c47da9c574b61415578e7fde8b126.png)
[self] - question brushing - peak value

Worthington丨Worthington胰蛋白酶抑制剂说明书

失败率高达80%,数字化转型如何正确完成战略规划?

【自】-刷题-动态规划
随机推荐
C language n*n matrix evaluation and inverse matrix [easy to understand]
VS2005透过SourceOffSite访问VSS2005的设置方法「建议收藏」
齐博建站指南(艾戈勒)
器利而工善,以RPA+LCAP赋能企业司库管理数字化升级
使用Pytorch快速训练网络模型
Worthington丨Worthington胰蛋白酶化学性质及相关研究
Pycharm new project
从XSS Payload学习浏览器解码
深度剖析集成学习Xgboost
新一代超安全蜂窝电池 思皓爱跑上市13.99万元起售
什么是驱动程序签名,驱动程序如何获取数字签名?
Okaleido生态核心权益OKA,尽在聚变Mining模式
NPDP考试需要携带什么?文具携带说明
pycharm配置运行环境
Merkle tree
SAP oracle 复制新实例后数据库远程连接报错 ora-01031
My second uncle is angry and swipes the screen all over the network. How can he cure my spiritual internal friction?
Solve thread safety problems & singleton mode
[self] - brush questions logic
Inspur clusterenginev4.0 remote command execution vulnerability cve-2020-21224