diff --git a/sik9252/MoveZeroes.js b/sik9252/MoveZeroes.js new file mode 100644 index 0000000..0d1091e --- /dev/null +++ b/sik9252/MoveZeroes.js @@ -0,0 +1,15 @@ +var moveZeroes = function (nums) { + let idx = 0; + + for (let i = 0; i < nums.length; i++) { + if (nums[i] !== 0) { + nums[idx] = nums[i]; + idx++; + } + } + + while (idx < nums.length) { + nums[idx] = 0; + idx++; + } +}; diff --git a/sik9252/PalindromeLinkedList.js b/sik9252/PalindromeLinkedList.js new file mode 100644 index 0000000..3085b6f --- /dev/null +++ b/sik9252/PalindromeLinkedList.js @@ -0,0 +1,19 @@ +var isPalindrome = function (head) { + const arr = []; + + while (head) { + arr.push(head.val); + head = head.next; + } + + let left = 0; + let right = arr.length - 1; + + while (left < right) { + if (arr[left] !== arr[right]) return false; + left++; + right--; + } + + return true; +};