예를 들어, t="3141592"이고 p="271" 인 경우, t의 길이가 3인 부분 문자열은 314, 141, 415, 159, 592입니다. 이 문자열이 나타내는 수 중 271보다 작거나 같은 수는 141, 159 2개 입니다.
-> 자세한 내용 보러가기
class Solution {
public int solution(String t, String p) {
int answer = 0;
int tLen = t.length();
int pLen = p.length();
for(int idx = 0; idx <= tLen - pLen ;idx++){
String str = t.substring(idx, idx + pLen);
if(str.compareTo(p) <= 0) answer++;
}
return answer;
}
}
class Solution {
public int solution(String t, String p) {
int answer = 0;
int tLen = t.length();
int pLen = p.length();
double pValue = Double.parseDouble(p);
for(int idx = 0; idx <= tLen - pLen ;idx++){
double tValue = Double.parseDouble(t.substring(idx, idx + pLen));
if(tValue <= pValue) answer++;
}
return answer;
}
}