deno.land / x / masx200_leetcode_test@10.6.5 / palindrome-linked-list / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { ListNode } from "../reverse-linked-list/ListNode.ts";import { ListNodeToArray } from "../reverse-linked-list/ListNodeToArray.ts";
export default function isPalindrome(head: ListNode | null): boolean { if (!head) return true; if (head.next === null) { return true; }
const vals = ListNodeToArray(head);
const half = Math.floor(vals.length / 2); for (let i = 0; i <= half; i++) { if (vals[i] !== vals[vals.length - 1 - i]) return false; } return true;}
masx200_leetcode_test

Version Info

Tagged at
a year ago