알고리즘
[프로그래머스] 크기가 작은 부분 문자열(Java) *
muerha
2024. 11. 27. 10:27

나의 풀이
class Solution {
public int solution(String t, String p) {
int answer = 0;
Long pLong = Long.parseLong(p);
for(int i = 0; i < t.length() - p.length() + 1 ; i++){
String str = t.substring(i, i + p.length());
if(Long.parseLong(str) <= pLong){
answer++;
}
}
return answer;
}
}
다른 사람의 풀이
class Solution {
public int solution(String t, String p) {
int answer = 0;
for (int i = 0; i < t.length()-p.length()+1; i++){
if (Long.parseLong(t.substring(i,i+p.length())) <= Long.parseLong(p)){
answer++;
}
}
return answer;
}
}