题解 | #最长无重复子数组#

最长无重复子数组

http://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4

import java.util.*;


public class Solution {
    public int maxLength (int[] arr) {
        Map<Integer,Integer> map = new HashMap<>();
        int size = 0;
        for(int i = 0; i<arr.length; i++){
            if(map.containsKey(arr[i])){
                if(map.size()>size){
                    size = map.size();
                }
                i = map.get(arr[i])+1;
                map = new HashMap<>();
            }
            map.put(arr[i],i);
        }
        return Math.max(size,map.size());
    }
}
全部评论

相关推荐

10-01 09:50
门头沟学院 Java
肖先生~:这个人真的很好,点赞
点赞 评论 收藏
分享
09-28 22:01
已编辑
广西科技大学 IT技术支持
合适才能收到offe...:找桌面运维?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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