C++)
#include <string>
#include <vector>
using namespace std;
int solution(string t, string p) {
int answer = 0;
int tLength = t.length();
int pLength = p.length();
for(int idx = 0; idx <= (tLength - pLength); idx++) {
if(t.substr(idx, pLength) <= p)
answer++;
}
return answer;
}
Python)
def solution(t, p):
ans = 0
for i in range(len(t)-len(p)+1):
if int(t[i:i+len(p)]) <= int(p):
ans += 1
return ans'프로그래머스 > Level1' 카테고리의 다른 글
| [Level1] 폰켓몬 (C++/Python) (0) | 2023.05.17 |
|---|---|
| [Level1] 비밀지도 (C++/Python) (0) | 2023.05.16 |
| [Level1] 문자열 내 마음대로 정렬하기 (C++/Python) (0) | 2023.05.14 |
| [Level1] 숫자 문자열과 영단어 (C++) (0) | 2023.05.13 |
| [Level1] 다트 게임 (C++) (0) | 2023.05.06 |