-
프로그래머스 / 햄버거 만들기코딩 테스트/Level 1 2022. 10. 27. 23:25반응형
https://school.programmers.co.kr/learn/courses/30/lessons/133502
파이썬
def solution(ingredient): stack = [] answer = 0 for each in ingredient: stack.append(each) if stack[-4:] == [1, 2, 3, 1]: answer += 1 del stack[-4:] return answer
코틀린
class Solution { fun solution(ingredient: IntArray): Int { var answer = 0 val bugger = listOf(1, 2, 3, 1) val stack = mutableListOf<Int>() for (each in ingredient) { stack.add(each) if (stack.size >= 4 && stack.slice(stack.size - 4 until stack.size) == bugger) { repeat(4) { stack.removeLast() } answer++ } } return answer } }
반응형