class Solution {
public int maxProfit(int[] prices) {
int res = 0;
int min = Integer.MAX_VALUE;
for (int i = 0; i
贪心就是贪局部最优解, 扩散到全局
class Solution {
public boolean canJump(int[] nums) {
int max_length = 0;
int i = 0;
for (; max_length >= i && i
max_length
来维护理论可达距离
class Solution {
public int jump(int[] nums) {
int n = nums.length;
int res = 0;
int curr = 0;
int nextCurr = 0;
for (int i = 0; i
curr
维护本次跳跃最大可达距离
nextCurr
通过遍历途经点, 维护下次跳跃最大可达距离
class Solution {
public List partitionLabels(String s) {
int n = s.length();
char[] charArray = s.toCharArray();
int[] last = new int[26];
for (int i = 0 ; i res = new ArrayList();
int start = 0;
int end = 0;
for (int i = 0; i
将字符串预处理, 产生每个字符的最大索引
提取[start,end]
范围内字符的最远索引来更新end
遇到这种熟悉又陌生的题型真别怕, 先把陌生数据转换成熟悉的, 这题就跟跳跃游戏II(045)一样了
参与评论
手机查看
返回顶部