题解 | #牛牛的协作#

牛牛的协作

https://www.nowcoder.com/practice/ae483ed148b34e14bec1451b3317984d

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param s string字符串 
     * @return int整型
     */
    public int lengthOfLongestContinuousTasks (String s) {
        // write code here
        int res = 0;
        char[] rec = s.toCharArray();
        HashMap<Character, Integer> map = new HashMap<>();
        int left = -1;
        for (int i = 0; i < rec.length; i++) {
            left = Math.max(map.getOrDefault(rec[i], -1), left);
            res = Math.max(res, i - left);
            map.put(rec[i], i);
        }
        return res;
    }
}

全部评论

相关推荐

代码飞升:别这样贬低自己,降低预期,放平心态,跟昨天的自己比。做好自己,反而会效率更高心态更好,加油兄弟
点赞 评论 收藏
分享
牛客96763241...:杭电✌️也是打完招呼,没人回吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务