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

最长无重复子数组

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

  1. 队列的创建 Queue que = new LinkListed<>(); 2.出队 que.poll();进队 que.add(c); 大小 que.size()
import java.util.*;


public class Solution {
    /**
     * 
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public int maxLength (int[] arr) {
        // write code here
        if(arr.length == 0)
            return 0;
        Queue<Integer> que = new LinkedList<Integer>();
        int res = 0;
        for ( int c : arr){
            while(que.contains(c)){
                que.poll();
            }
            que.add(c);
            res = Math.max(res,que.size());
        }
        return res;
        
    }

}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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