728x90
SMALL

using System;

public class Solution {
    public int solution(int order) {
        int answer = 0;
        int length = order.ToString().Length;

//order의 string 상의 길이를 추출한다.
        
        for(int i=1;i<=length;i++)
        {
            if(order%10 == 3 || order%10 == 6 || order%10 == 9)
            {
                answer++;
            }
            order = order/10;
        }
        //나머지가 3,6,9인 경우를 추출하여 answer++해준다.
        return answer;
    }
}

 

파이썬

/////

def solution(order):
    answer = 0
    order = str(order)
    return order.count('3') + order.count('6') + order.count('9')

////

def solution(order):
    answer = len([1 for ch in str(order) if ch in "369"])
    return answer

/////

def solution(order):
    return sum(map(lambda x: str(order).count(str(x)), [3, 6, 9]))

 

자바

////

 

class Solution {
    public int solution(int order) {
        int answer = 0;
        int count = 0;
        while(order != 0)
        {
            if(order % 10 == 3 || order % 10 == 6 || order % 10 == 9)
            {
                count++;
            }
             order = order/10;
        }
        answer = count;
        return answer;
    }
}

 

 

728x90

설정

트랙백

댓글