728x90
SMALL

using System;

public class Solution {
    public int solution(int n) {
        int answer = 0;
        
        for(int i=1;i<=n;i++)
        {
            answer++;


            if(i%3 == 0 || i%10 == 3 || (i/10)%10 == 3)
            {
                n++;
            }
        }
        
        return answer;
    }
}

 

 

자바

 

 

class Solution {
    public int solution(int n) {
        int answer = 0;

        for (int i = 1; i <= n; i++) 
        {
            answer++;
            
            if (answer % 3 == 0 || String.valueOf(answer).contains("3")) 
            {
                i--;
            }
        }

        return answer;
    }
}

 

 

class Solution {
    public int solution(int n) {
        String str;
        
        for (int i = 1; i <= n; i++)
        {
            str = ""+i;
            
            if(str.contains("3") || i%3 == 0) 
              n++;
        }
        
        return n;     
    }
}
728x90

설정

트랙백

댓글