diff --git a/HamSungJun/LinkedList/Solution_1290.ts b/HamSungJun/LinkedList/Solution_1290.ts new file mode 100644 index 0000000..67ac145 --- /dev/null +++ b/HamSungJun/LinkedList/Solution_1290.ts @@ -0,0 +1,19 @@ +function getDecimalValue (head: ListNode | null): number { + let isOneBitOccurred = false + let out = '' + let temp = head + while (temp !== null) { + if (temp.val === 1) { + isOneBitOccurred = true + out += '1' + } else if (temp.val === 0 && isOneBitOccurred) { + out += '0' + } + temp = temp.next + } + let acc = 0 + for (let i = 0; i < out.length; i++) { + acc += (2 ** (out.length - 1 - i)) * parseInt(out[i]) + } + return acc +}; diff --git a/HamSungJun/LinkedList/Solution_237.ts b/HamSungJun/LinkedList/Solution_237.ts new file mode 100644 index 0000000..bf5bccf --- /dev/null +++ b/HamSungJun/LinkedList/Solution_237.ts @@ -0,0 +1,19 @@ +/** + * Definition for singly-linked list. + * class ListNode { + * val: number + * next: ListNode | null + * constructor(val?: number, next?: ListNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + * } + */ + +/** + Do not return anything, modify it in-place instead. + */ +function deleteNode (root: ListNode | null): void { + root.val = root.next.val + root.next = root.next.next +}; diff --git a/HamSungJun/LinkedList/Solution_876.ts b/HamSungJun/LinkedList/Solution_876.ts new file mode 100644 index 0000000..b598dd2 --- /dev/null +++ b/HamSungJun/LinkedList/Solution_876.ts @@ -0,0 +1,29 @@ +/** + * Definition for singly-linked list. + * class ListNode { + * val: number + * next: ListNode | null + * constructor(val?: number, next?: ListNode | null) { + * this.val = (val===undefined ? 0 : val) + * this.next = (next===undefined ? null : next) + * } + * } + */ + +function middleNode (head: ListNode | null): ListNode | null { + let lenList = 1 + let temp = head + while (temp.next !== null) { + temp = temp.next + lenList += 1 + } + + temp = head + const mid = (lenList % 2 !== 0) ? Math.ceil(lenList / 2) : (lenList / 2) + 1 + let count = 1 + while (count < mid) { + temp = temp.next + count += 1 + } + return temp +};