当前位置:网站首页>2022.04.23(LC_763_划分字母区间)
2022.04.23(LC_763_划分字母区间)
2022-04-23 18:51:00 【Leeli9316】

方法:贪心

class Solution {
public List<Integer> partitionLabels(String s) {
//记录每个字母出现的最后位置
int[] lastPos = new int[26];
for (int i = 0; i < s.length(); i++) {
lastPos[s.charAt(i) - 'a'] = i;
}
List<Integer> ans = new ArrayList<>();
int start = 0; //开始位置
int end = 0; //结束位置
for (int i = 0; i < s.length(); i++) {
//更新字符出现的最远位置
end = Math.max(end, lastPos[s.charAt(i) - 'a']);
if (i == end) {
ans.add(end - start + 1);
start = i + 1;
}
}
return ans;
}
}
版权声明
本文为[Leeli9316]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Leeli9316/article/details/124360610
边栏推荐
- With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
- Chondroitin sulfate in vitreous
- Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
- ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
- Usage of functions decode() and replace() in SQL
- After CANopen starts PDO timing transmission, the heartbeat frame time is wrong, PDO is delayed, and CANopen time axis is disordered
- Introduction to ROS learning notes (II)
- Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
- Esp32 (UART 485 communication) - 485 communication of serial port (3)
- Daily CISSP certification common mistakes (April 19, 2022)
猜你喜欢

The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an

七、DOM(下) - 章节课后练习题及答案

Iptables - L executes slowly

MVVM model

listener. log

With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate

Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash

Eight bit binary multiplier VHDL

根据快递单号查询物流查询更新量

昇腾 AI 开发者创享日全国巡回首站在西安成功举行
随机推荐
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
Download xshell 6 and xftp6 official websites
ESP32 LVGL8. 1 - bar progress bar (bar 21)
Druid SQL和Security在美团点评的实践
With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
Go language GUI framework Fyne Chinese garbled or not displayed
Can filter
电路在线模拟
Machine learning theory (8): model integration ensemble learning
Database computer experiment 4 (data integrity and stored procedure)
机器学习实战 -朴素贝叶斯
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Advanced transfer learning
Daily network security certification test questions (April 18, 2022)
Sentinel service fusing practice (sentinel integration ribbon + openfeign + fallback)
mysql_linux版本的下载及安装详解
关于unity文件读取的操作(一)
22 year flying Book manpower Kit
Machine learning practice - naive Bayes
STM32: LCD显示