Skip to content

Commit 3522f19

Browse files
authored
Create 234-palindrome-linked-list.js
1 parent 26223ed commit 3522f19

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

234-palindrome-linked-list.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val) {
4+
* this.val = val;
5+
* this.next = null;
6+
* }
7+
*/
8+
/**
9+
* @param {ListNode} head
10+
* @return {boolean}
11+
*/
12+
const isPalindrome = function(head) {
13+
const arr = []
14+
while(head != null) {
15+
arr.push(head.val)
16+
head = head.next
17+
}
18+
let start = 0
19+
let end = arr.length - 1
20+
while(start < end) {
21+
if(arr[start] !== arr[end]) {
22+
return false
23+
}
24+
start++
25+
end--
26+
}
27+
return true
28+
};

0 commit comments

Comments
 (0)