알고리즘
isPalindromeLL
Hot Dobby
2020. 11. 16. 22:06
const isPalindromeLL = function (head) {
let arr = [];
while (head !== null) {
arr.push(head.value);
head = head.next;
//헤드가 끝날떄까지 계속 옮긴다.
}
for (let i = 0; i < arr.length / 2; i++) {
if (arr[i] !== arr[arr.length - i - 1]) return false;
}
//만든 배열을 가지고 앞과 뒤에서 비교하면서 틀려지는 순간 false를 부여한다!
return true;
};