Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions HamSungJun/LinkedList/Solution_1290.ts
Original file line number Diff line number Diff line change
@@ -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
};
19 changes: 19 additions & 0 deletions HamSungJun/LinkedList/Solution_237.ts
Original file line number Diff line number Diff line change
@@ -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
};
29 changes: 29 additions & 0 deletions HamSungJun/LinkedList/Solution_876.ts
Original file line number Diff line number Diff line change
@@ -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
};