题解 | #最长不重复子数组长度问题#最简单做法
最长不重复子数组长度问题
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
if (nums.length == 0 || nums == null) {
return 0;
}
int max = 1;
for (int i = 0; i < nums.length; i++) {
ArrayList<Integer> list = new ArrayList<Integer> ();
for (int j = 0; j <= i; j++) {
if (list.contains(nums[j])) {
list = new ArrayList<Integer> ();
break;
} else {
list.add(nums[j]);
if (list.size() > max) {
max = list.size();
}
}
}
}
return max;
}
}
