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
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"@typescript-eslint"
],
"rules": {
"max-len": 0
"max-len": 0,
"indent": "off",
"@typescript-eslint/indent": ["error"]
}
}
21 changes: 21 additions & 0 deletions HamSungJun/Solution_1688.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function numberOfMatches (n: number): number {
/**
* 남은 토너먼트 팀이 짝수일때와 홀수일때
* 필요한 연산을 진행하여 매치 카운트를 증가
* 이후 승자팀이 결정되었을 때 카운트를 반환.
*/
let numTeams = n
let matchCount = 0
while (numTeams > 1) {
if (numTeams % 2 === 0) {
numTeams /= 2
matchCount += numTeams
} else {
numTeams = (numTeams - 1) / 2 + 1
matchCount += numTeams - 1
}
}
return matchCount
};

numberOfMatches(7)
21 changes: 21 additions & 0 deletions HamSungJun/Solution_1725.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function countGoodRectangles (rectangles: number[][]): number {
/**
* 1. 두 사이드의 길이중 작은 값을 선택하면서 등장한 작은 값중 최대값을 기억
* 2. 작은 값으로 선택된 리스트를 순회하면서 원소별 등장 갯수를 확인
* 3. 기억해둔 최대값을 Map에 조회하여 답안을 반환
*/
let maxLen = Number.MIN_SAFE_INTEGER
const cuts = rectangles.map(rect => {
const maxSideLength = Math.min(rect[0], rect[1])
maxLen = Math.max(maxLen, maxSideLength)
return maxSideLength
}).reduce((acc, curr) => {
if (acc.has(curr)) {
acc.set(curr, acc.get(curr) + 1)
} else {
acc.set(curr, 1)
}
return acc
}, new Map())
return cuts.get(maxLen)
};
31 changes: 31 additions & 0 deletions HamSungJun/Solution_1844.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function replaceDigits (s: string): string {
/**
* 1. 클로저 내부 캐쉬용도로 사용할 Map 자료구조 배치.
* 2. shift 연산이 많아질 수록 캐쉬에 등록해둔 결과 값이 많아지므로
* 3. 이후 인풋의 크기가 커질 수록 성능상에서 유리해질 수 있을것이라 생각함.
*/
const cachedConverter = cachedFn()
let out = ''
for (let i = 0; i < s.length; i++) {
const nextCharCode = s[i].charCodeAt(0)
if (nextCharCode >= 48 && nextCharCode <= 57) {
out += cachedConverter(s[i - 1], +s[i])
} else {
out += s[i]
}
}
return out
};

function cachedFn () {
const cacheMap: Map<string, string> = new Map()
return (alpha: string, shiftDiff: number) => {
const cacheKey = alpha + shiftDiff
if (!cacheMap.has(cacheKey)) {
cacheMap.set(cacheKey, String.fromCharCode(alpha.charCodeAt(0) + shiftDiff))
}
return cacheMap.get(cacheKey)
}
}

console.log(replaceDigits('a1b2c3d4e'))