빙응의 공부 블로그
[Programmers]Lv.1 크기가 작은 부분 문자열 본문

📝풀이
평범한 문자열 문제
1. length()
2. chatAt()
3. 타입 변환
3개를 가지고 잘 구현하면 된다.
단 첫 시도에서 런타임에러가 나왔다.
이유는 p가 18까지라서 int 말고 long을 사용해야 하기 때문이다.
class Solution {
public int solution(String t, String p) {
int leng = p.length();
int answer = 0;
int count = t.length() - leng+ 1; //반복 횟수
for (int i = 0; i < count ; i++) {
String temp = "";
for (int j = 0; j < leng; j++) {
temp += t.charAt(i + j);
}
if(Long.parseLong(temp) <= Long.parseLong(p)) {
answer++;
}
}
return answer;
}
}
'Argorithm' 카테고리의 다른 글
[Programmers]LV.1 문자열 나누기 (1) | 2023.12.06 |
---|---|
[Programmers]LV.1 가장 가까운 같은 글자 (0) | 2023.12.04 |
[Programmers]Lv.1 개인정보 수집 유효기간 (0) | 2023.12.01 |
[Programmers]LV.1 둘만의 암호 (0) | 2023.11.30 |
[Programmers]LV.1 카드 뭉치 (1) | 2023.11.30 |