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
10 changes: 10 additions & 0 deletions HamSungJun/Solution_1791.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function findCenter (edges: number[][]): number {
/**
* 첫번째 엣지의 숫자들을 Set에 매겨놓고
* 두번째 엣지에서 다시 등장한 버텍스가
* 반드시 중점 버텍스가 된다.
*/
const set = new Set(edges[0])
const [u, v] = edges[1]
return set.has(u) ? u : v
};
14 changes: 14 additions & 0 deletions HamSungJun/Solution_1859.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function sortSentence (s: string): string {
/**
* 끝자리 숫자를 기준으로 정렬
* 조인하여 반환된 문자열에서 정규식 매칭을 통해
* 숫자를 전부 제거하면 정렬된 문자열만 남아 반환됨.
*/
const sArr = s.split(' ')
sArr.sort((a, b) => {
const rankA = +a[a.length - 1]
const rankB = +b[b.length - 1]
return Number(rankA > rankB) - Number(rankA < rankB)
})
return sArr.join(' ').replace(/\d/g, '')
};
26 changes: 26 additions & 0 deletions HamSungJun/Solution_938.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
interface RangeCondition {
low: number;
high: number;
}

function rangeSumBST (root: TreeNode | null, low: number, high: number): number {
/**
* 1. InOrder(Left -> Root -> Right) 으로 순회한다.
* 2. low <= val && <= hight 의 값이면 배열에 Push
* 3. 배열에 취합된 값들을 더하여 리턴.
*/
const l1: number[] = []
recRangeSum(root, { low, high }, l1)
return l1.reduce((acc, curr) => (acc += curr), 0)
};

function recRangeSum (root: TreeNode | null, { low, high }: RangeCondition, list: number[]): void {
if (!root) return
recRangeSum(root.left, { low, high }, list)
const nodeValue = root.val
if (low <= nodeValue && nodeValue <= high) {
list.push(nodeValue)
}

recRangeSum(root.right, { low, high }, list)
}