File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 37
37
217|[ Contains Duplicate] ( ./0217-contains-duplicate.js ) |Easy|
38
38
219|[ Contains Duplicate II] ( ./0219-contains-duplicate-ii.js ) |Easy|
39
39
226|[ Invert Binary Tree] ( ./0226-invert-binary-tree.js ) |Easy|
40
+ 234|[ Palindrome Linked List] ( ./0234-palindrome-linked-list.js ) |Easy|
40
41
263|[ Ugly Number] ( ./0263-ugly-number.js ) |Easy|
41
42
264|[ Ugly Number II] ( ./0264-ugly-number-ii.js ) |Medium|
42
43
268|[ Missing Number] ( ./0268-missing-number.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments