题解 | #最长无重复子数组#
最长无重复子数组
http://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4
import java.util.*;
public class Solution {
/**
*
* @param arr int整型一维数组 the array
* @return int整型
*/
public int maxLength (int[] arr) {
// write code here
if (arr == null || arr.length == 0) {
return 0;
}
int left = 0, result = 0;
for (int i = 0, len = arr.length; i < len; i++) {
for (int inner = left; inner < i; inner++) {
if (arr[inner] == arr[i]) {
result = Math.max(result, i - left);
left = inner+1;
}
}
}
return Math.max(result, arr.length - left);
}
}