题解 | #最长不重复子数组长度问题#
最长不重复子数组长度问题
https://www.nowcoder.com/practice/2b97599367784237aadac4de2008829d
直接借用队列 一步到位解决
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int整型一维数组
* @return int整型
*/
public int longestUniqueSubarrayLength (int[] nums) {
// write code here 队列解决
int max = 0;
Queue<Integer> q1 = new LinkedList<>();
for(int a : nums ){
while(q1.contains(a)){
q1.poll();
}
q1.offer(a);
max = Math.max(max, q1.size());
}
return max;
}
}
