ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 프로그래머스 / 옹알이 (2)
    코딩 테스트/Level 1 2022. 10. 27. 23:16
    반응형

    https://school.programmers.co.kr/learn/courses/30/lessons/133499

    파이썬

    def solution(babbling):
        answer = 0
        for each in babbling:
            for index, text in enumerate(("aya", "ye", "woo", "ma")):
                each = each.replace(text, str(index))
            if each.isdigit():
                if '00' not in each:
                    if '11' not in each:
                        if '22' not in each:
                            if '33' not in each:
                                answer += 1
        return answer

    코틀린

    class Solution {
        fun solution(babbling: Array<String>): Int {
            var answer: Int = 0
            for (it in babbling) {
                var temp = it
                for ((index, each) in arrayOf("aya", "ye", "woo", "ma").withIndex()) {
                    temp = temp.replace(each, index.toString())
                }
                if (temp.toIntOrNull() != null)
                    if (!("00" in temp || "11" in temp || "22" in temp || "33" in temp))
                        answer++
            }
            return answer
        }
    }
    class Solution {
        fun solution(babbling: Array<String>): Int {
            val words = arrayOf("aya", "ye", "woo", "ma")
            return babbling.map {
                var temp = it
                words.withIndex().forEach { (index, each) ->
                    temp = temp.replace(each, index.toString())
                }.let { temp }
            }.count { !(it.toIntOrNull() == null || "00" in it || "11" in it || "22" in it || "33" in it) }
        }
    }
    class Solution {
        fun solution(babbling: Array<String>) = babbling.map {
            var temp = it
            arrayOf("aya", "ye", "woo", "ma").withIndex().forEach { (index, each) ->
                temp = temp.replace(each, index.toString())
            }.let { temp }
        }.count { !(it.toIntOrNull() == null || "00" in it || "11" in it || "22" in it || "33" in it) }
    }
    반응형
Designed by Tistory.