Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[전현수] 기적의 매매법, 수 이어 쓰기 1, 등수 구하기, DNA #62

Merged
merged 14 commits into from
Jan 1, 2023

Conversation

soopeach
Copy link
Member

@soopeach soopeach commented Dec 25, 2022

📌 from issue #61 📌

📋문제 목록📋

기적의 매매법: ✅
수 이어 쓰기 1: ✅
등수 구하기: ✅
DNA: ⛔️

📍추가로 해결한 문제📍

📝메모

  • DNA 문제를 이해 못해서 정말 시간을 많이 버렸습니다.... 제 문해력이 딸리는 건지...
    혹시 저 같으신 분이 있으실까봐 문제의 이해를 위해 참고한 블로그 링크 남겨봅니다!!! (구현 자체는 쉬웠어용)
    DNA 문제 이해가 안되어서 참고한 곳

  • 투 포인터 연습할라고 문제 조금 더 풀었슴다..


@soopeach soopeach self-assigned this Dec 25, 2022
Comment on lines +16 to +32
data class Wallet(
var remainedCash: Int = 0,
var ownedStockCnt: Int = 0,
) {

fun sellStock(price: Int) {
remainedCash += ownedStockCnt * price
ownedStockCnt = 0
}

fun buyStock(price: Int) {
ownedStockCnt += remainedCash / price
remainedCash %= price
}

fun getStockWorth(price: Int) = ownedStockCnt * price + remainedCash
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굉장히 깔끔합니다 👍

for (j in 0 until dnaCnt) {
val curAlphabet = dnaList[j][i]
alphabetMap[curAlphabet] =
alphabetMap.getOrDefault(curAlphabet, 0) + 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getOrDefault 사용 배우고 갑니다!

Comment on lines +37 to +39
hammingDistance +=
alphabetMap.filter { it.key != mostFrequentAlphabet }
.map { it.value }.sum()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sum으로 다른걸 더하는 것보다 max인 value를 dnaCnt에서 빼도 될 것 같습니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeeminimini
좋은 방법 감사합니다!!

} else {
repeat(digit) { zeroCnt ->
answer += if (zeroCnt == 0) 9
else ("9" + "0".repeat(zeroCnt)).toInt() * (zeroCnt + 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문자열로 repeat하신게 인상깊었습니당

Copy link
Contributor

@bngsh bngsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13문제 존경합니다...

Comment on lines +26 to +29
fun buyStock(price: Int) {
ownedStockCnt += remainedCash / price
remainedCash %= price
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 파는 부분은 성민이만 필요하길래 따로 함수로 안 뺐는데 둘다 빼주는게 추상화 레벨(?)이 맞아서 더 깔끔했겠다는 생각을 했습니다

.sortedByDescending { it }

newList
.lastIndexOf(newScore).apply {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고차함수를 쓰니 이렇게 깔꼼하게 풀리는 문제였군요...


val mostFrequentAlphabet = alphabetMap
.toSortedMap()
.maxBy { it.value }.key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고차함수란 어렵네요...

Comment on lines +21 to +29
fun sellStock(price: Int) {
remainedCash += ownedStockCnt * price
ownedStockCnt = 0
}

fun buyStock(price: Int) {
ownedStockCnt += remainedCash / price
remainedCash %= price
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미리 함수로 빼둔 게 좋네요

Comment on lines +30 to +31
newList.indexOf(newScore).apply {
println(this + 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastIndexOf 랑 indexOf 나눈 게 좋습니다!!

@soopeach soopeach merged commit 1a20fdd into main Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants