From 2a94355b38b3041aa356d0fd17bc563e782d91b8 Mon Sep 17 00:00:00 2001 From: tgyuuAn Date: Sun, 6 Oct 2024 11:30:58 +0900 Subject: [PATCH] 2024-10-06 --- tgyuuAn/README.md | 1 + ...60\353\234\250\353\246\254\352\270\260.kt" | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 "tgyuuAn/\352\267\270\353\246\254\353\224\224/\355\222\215\354\204\240 \355\204\260\353\234\250\353\246\254\352\270\260.kt" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index d91cf49..1b566ff 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -83,4 +83,5 @@ | 74차시 | 2024.08.30 | BFS | 불 켜기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/242 | 75차시 | 2024.09.02 | DP | 산 모양 타일링 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/243 | 76차시 | 2024.09.06 | DFS + 트리 | 표현 가능한 이진트리 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/246 +| 78차시 | 2024.10.06 | 그리디 | 풍선 터뜨리기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/250 --- diff --git "a/tgyuuAn/\352\267\270\353\246\254\353\224\224/\355\222\215\354\204\240 \355\204\260\353\234\250\353\246\254\352\270\260.kt" "b/tgyuuAn/\352\267\270\353\246\254\353\224\224/\355\222\215\354\204\240 \355\204\260\353\234\250\353\246\254\352\270\260.kt" new file mode 100644 index 0000000..83a0a69 --- /dev/null +++ "b/tgyuuAn/\352\267\270\353\246\254\353\224\224/\355\222\215\354\204\240 \355\204\260\353\234\250\353\246\254\352\270\260.kt" @@ -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 + } +} \ No newline at end of file