当前位置:网站首页>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
边栏推荐
- Codeforces Round #474 (Div. 1 + Div. 2) - C, F
- Blocking queue
- OpenCV宏定义
- 简述分组密码的加密分组链接模式的工作原理及其特点(密码学移位密码加密解密)
- 控件 圆角描边 MaterialShapeDrawable
- GhostNets on Heterogeneous Devices via Cheap Operations
- [self] - question brushing - string
- Multi sensor fusion positioning (II) -- map based positioning
- PMP考试倒计时,速看3A通关锦囊!
- 数据中台的那些“经验与陷阱”
猜你喜欢
随机推荐
EN 12101-8:2011烟雾和热量控制系统防烟挡板—CE认证
Zero view h5s video platform getUserInfo information disclosure vulnerability cnvd-2020-67113
Hutool official website (is hutool easy to use)
机器学习问题笔记
E-commerce data model design
MySQL log management, backup and recovery
Wildcard ssl/tls certificate
Compatibility description between kingbasees and Oracle (3. Common functions)
Deep analysis of integrated learning AdaBoost
剑指 Offer 41. 数据流中的中位数
Class, leetcode919 -- complete binary tree inserter
台式机dp接口在哪(主机没有dp接口怎么办)
通配符 SSL/TLS 证书
VS2005透过SourceOffSite访问VSS2005的设置方法「建议收藏」
Zabbix 5.0 使用自带Redis模版监控
2022 G2 power plant boiler stoker examination question bank simulated examination platform operation
Fundamental inquiry binary tree
The computer doesn't know what to uninstall, can't open the calculator, can't edit screenshots, can't open txt files, and so on
RHCE first day
A new generation of ultra safe cellular battery, Sihao aipao, will be available from 139900 yuan









