-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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 | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOrDefault 사용 배우고 갑니다!
hammingDistance += | ||
alphabetMap.filter { it.key != mostFrequentAlphabet } | ||
.map { it.value }.sum() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sum으로 다른걸 더하는 것보다 max인 value를 dnaCnt에서 빼도 될 것 같습니다!
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
문자열로 repeat하신게 인상깊었습니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
13문제 존경합니다...
fun buyStock(price: Int) { | ||
ownedStockCnt += remainedCash / price | ||
remainedCash %= price | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고차함수란 어렵네요...
fun sellStock(price: Int) { | ||
remainedCash += ownedStockCnt * price | ||
ownedStockCnt = 0 | ||
} | ||
|
||
fun buyStock(price: Int) { | ||
ownedStockCnt += remainedCash / price | ||
remainedCash %= price | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
미리 함수로 빼둔 게 좋네요
newList.indexOf(newScore).apply { | ||
println(this + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastIndexOf 랑 indexOf 나눈 게 좋습니다!!
📌 from issue #61 📌
📋문제 목록📋
📍추가로 해결한 문제📍
📝메모
DNA 문제를 이해 못해서 정말 시간을 많이 버렸습니다.... 제 문해력이 딸리는 건지...
혹시 저 같으신 분이 있으실까봐 문제의 이해를 위해 참고한 블로그 링크 남겨봅니다!!! (구현 자체는 쉬웠어용)
DNA 문제 이해가 안되어서 참고한 곳
투 포인터 연습할라고 문제 조금 더 풀었슴다..