File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 1
1
package easy
2
2
3
+ import LinkedListTopic
4
+ import StackTopic
5
+ import TwoPointersTopic
3
6
import utils.ListNode
4
7
5
8
/* *
@@ -9,18 +12,18 @@ import utils.ListNode
9
12
* Given the head of a singly linked list, return true if it is a palindrome.
10
13
*/
11
14
12
- class Easy234 {
15
+ class Easy234 : LinkedListTopic , TwoPointersTopic , StackTopic {
13
16
14
17
fun isPalindrome (head : ListNode ? ): Boolean {
15
18
if (head == null ) return true
16
- val resultList = ArrayList <Int >()
17
- var currentNode = head
18
- while (currentNode != null ) {
19
- resultList .add(currentNode .`val `)
20
- currentNode = currentNode .next
19
+ val list = ArrayList <Int >()
20
+ var node = head
21
+ while (node != null ) {
22
+ list .add(node .`val `)
23
+ node = node .next
21
24
}
22
- for (i in 0 .. resultList .size / 2 ) {
23
- if (resultList [i] != resultList[resultList .size - 1 - i]) {
25
+ for (i in 0 .. list .size / 2 ) {
26
+ if (list [i] != list[list .size - 1 - i]) {
24
27
return false
25
28
}
26
29
}
You can’t perform that action at this time.
0 commit comments