Skip to content

Commit 9990f30

Browse files
committed
Add solution #234
1 parent 14e7638 commit 9990f30

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
217|[Contains Duplicate](./0217-contains-duplicate.js)|Easy|
3838
219|[Contains Duplicate II](./0219-contains-duplicate-ii.js)|Easy|
3939
226|[Invert Binary Tree](./0226-invert-binary-tree.js)|Easy|
40+
234|[Palindrome Linked List](./0234-palindrome-linked-list.js)|Easy|
4041
263|[Ugly Number](./0263-ugly-number.js)|Easy|
4142
264|[Ugly Number II](./0264-ugly-number-ii.js)|Medium|
4243
268|[Missing Number](./0268-missing-number.js)|Easy|
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 234. Palindrome Linked List
3+
* https://leetcode.com/problems/palindrome-linked-list/
4+
* Difficulty: Easy
5+
*
6+
* Given the `head` of a singly linked list, return `true` if it is a palindrome.
7+
*/
8+
9+
/**
10+
* Definition for singly-linked list.
11+
* function ListNode(val, next) {
12+
* this.val = (val===undefined ? 0 : val)
13+
* this.next = (next===undefined ? null : next)
14+
* }
15+
*/
16+
/**
17+
* @param {ListNode} head
18+
* @return {boolean}
19+
*/
20+
var isPalindrome = function(head) {
21+
let a = '', b = '';
22+
23+
while (head) {
24+
a = a + head.val;
25+
b = head.val + b;
26+
head = head.next;
27+
}
28+
29+
return a === b;
30+
};

0 commit comments

Comments
 (0)