favicon Jay Lee DevLog

📚 목차
#include <string>
#include <vector>

using namespace std;

int solution(vector<int> array) {
    int answer = 0;
    for(auto i : array)
    {
        string strValue = to_string(i);
        for(auto j : strValue)
        {
            if (j == '7')
                answer++;   
        }
    }
    return answer;
}

이건 예전에

내가 KT 코딩테스트할 때

비슷한 문제가 나왔었던 것 같다.

그때 문제가 특정 숫자까지 특정 값이 몇번 나오냐

이런거였던거 같은데..

 

문제 풀이는

숫자를 String으로 바꿔서

문자 '7'을 찾는 형태로 풀었다.

 

이번 문제는 int의 string 변환이

핵심이 아닐까 싶다.

+ Recent posts

/ /

Contact

📧 dlwjdwls60@naver.com


블로그에 내용이 있으면 해당 글을 보여주며, 없으면 내용이 복사된 채로 ChatGPT로 연결됩니다.