当前位置:网站首页>2022.04.23 (lc_763_divided into letter interval)
2022.04.23 (lc_763_divided into letter interval)
2022-04-23 18:53:00 【Leeli9316】

Method : greedy

class Solution {
public List<Integer> partitionLabels(String s) {
// Record the last position of each letter
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; // Starting position
int end = 0; // End position
for (int i = 0; i < s.length(); i++) {
// Update the farthest position where the character appears
end = Math.max(end, lastPos[s.charAt(i) - 'a']);
if (i == end) {
ans.add(end - start + 1);
start = i + 1;
}
}
return ans;
}
}
版权声明
本文为[Leeli9316]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231851339617.html
边栏推荐
- Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.
- ESP32 LVGL8. 1 - textarea text area (textarea 26)
- 在渤海期货办理开户安全吗。
- The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
- Domestic GD chip can filter
- MySQL Téléchargement et installation de la version Linux
- Fundamentals of machine learning theory -- some terms about machine learning
- Machine learning theory (8): model integration ensemble learning
- Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
- 根据快递单号查询物流查询更新量
猜你喜欢

MVVM模型

ESP32 LVGL8. 1 - label (style 14)

2022.04.23(LC_714_买卖股票的最佳时机含手续费)

Esp32 (UART 485 communication) - 485 communication of serial port (3)

mysql_ Download and installation of Linux version

教你用简单几个步骤快速重命名文件夹名

MySQL学习第五弹——事务及其操作特性详解

Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time

Simplified path (force buckle 71)

ESP32 LVGL8. 1 - arc (arc 19)
随机推荐
解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
Excel intercept text
#yyds干货盘点#stringprep --- 因特网字符串预备
Recyclerview control list item layout match_ Fundamental principle of parent attribute invalidation
Dynamically add and delete layouts
RPM package management
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
Go language GUI framework Fyne Chinese garbled or not displayed
On iptables
ESP32 LVGL8. 1 - img picture (IMG 20)
mysql_linux版本的下載及安裝詳解
纠结
Database computer experiment 4 (data integrity and stored procedure)
电路在线模拟
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 LVGL8. 1 - BTN button (BTN 15)
K210串口通信
Get a list of recent apps
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
Raspberry pie uses root operation, and the graphical interface uses its own file manager