JS算法总结

JS算法总结

链表题

  1. 链表转数组

场景:要使用栈方法时

1
2
3
4
5
6
var isPalindrome = function (head) {
const vals = [];
while (head !== null) {
vals.push(head.val)//压入值,把链表转化为数组
head = head.next
}