Skip to content

Commit

Permalink
2024-10-06
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Oct 6, 2024
1 parent 8e74983 commit 2a94355
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@
| 74차시 | 2024.08.30 | BFS | <a href="https://www.acmicpc.net/problem/11967">불 켜기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/242
| 75차시 | 2024.09.02 | DP | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/258705">산 모양 타일링</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/243
| 76차시 | 2024.09.06 | DFS + 트리 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/150367">표현 가능한 이진트리</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/246
| 78차시 | 2024.10.06 | 그리디 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/68646">풍선 터뜨리기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/250
---
39 changes: 39 additions & 0 deletions tgyuuAn/그리디/풍선 터뜨리기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Solution {
fun solution(a: IntArray): Int {
val _min = a.minOrNull() ?: return 0

var ltrAnswer = 0
var ltrPrevious = a[0]
for((idx, ltrNum) in a.withIndex()){
if(ltrNum == _min) break

if(idx == 0) {
ltrAnswer += 1
continue
}

if(ltrPrevious > ltrNum){
ltrAnswer += 1
ltrPrevious = ltrNum
}
}

var rtlAnswer = 0
var rtlPrevious = a[a.size-1]
for((idx, rtlNum) in a.reversed().withIndex()){
if(rtlNum == _min) break

if(idx == 0) {
rtlAnswer += 1
continue
}

if(rtlPrevious > rtlNum){
rtlAnswer += 1
rtlPrevious = rtlNum
}
}

return ltrAnswer + rtlAnswer + 1
}
}

0 comments on commit 2a94355

Please sign in to comment.