Skip to content

Commit d70e99a

Browse files
author
kkarpyshev
committed
Easy234 challenge
1 parent c0b0737 commit d70e99a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/easy/234. Palindrome Linked List .kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package easy
22

3+
import LinkedListTopic
4+
import StackTopic
5+
import TwoPointersTopic
36
import utils.ListNode
47

58
/**
@@ -9,18 +12,18 @@ import utils.ListNode
912
* Given the head of a singly linked list, return true if it is a palindrome.
1013
*/
1114

12-
class Easy234 {
15+
class Easy234 : LinkedListTopic, TwoPointersTopic, StackTopic {
1316

1417
fun isPalindrome(head: ListNode?): Boolean {
1518
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
2124
}
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]) {
2427
return false
2528
}
2629
}

0 commit comments

Comments
 (0)