-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathP06.java
34 lines (29 loc) · 878 Bytes
/
P06.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.absurd.np.prologLists;
import java.util.List;
/**
* @author <a href="mailto:www_1350@163.com">Absurd</a>
* @version V1.0
* @Title: 99-problems
* @Package com.absurd.np
* @Description:
* Find out whether a list is a palindrome
* @date 2016/10/20 10:18
*/
public class P06 {
public static <T> boolean isPalindrome(List<T> list){
if(list == null){
throw new IllegalArgumentException("list can't be null");
}
int size = list.size();
for (int i = 0; i < size/2; i++) {
if(!list.get(i) .equals(list.get(size-1-i))) return false;
}
return true;
}
public static <T> boolean isPalindrome_Stream(List<T> list){
if(list == null){
throw new IllegalArgumentException("list can't be null");
}
return P05.reverseStream(list).equals(list);
}
}