class Solution {
public int solution(String myString, String pat) {
myString = myString.replace("A", "c").replace("B", "A").replace("c", "B");
for(int i=0; i<=myString.length()-pat.length(); i++) {
if(myString.substring(i, i+pat.length()).equals(pat)) {
return 1;
}
}
return 0;
}
}
짧게 만들기
class Solution {
public int solution(String myString, String pat) {
myString = myString.replace("A", "c").replace("B", "A").replace("c", "B");
return myString.contains(pat) ? 1 : 0;
}
}
String class 메서드에 replace와 contains가 있다는 사실을 자꾸 잊어버림...
String class method()
- charAt
- compareTo
- concat
- indexOf
- split
- substring
- toUpperCase / toLowerCase
- trim
- length
- isEmpty
- isBlank
- startsWith / endsWith
- equals
- contains
- replace / replaceAll
- format
etc ...
'Study with me > 프로그래머스 L0 마스터하기' 카테고리의 다른 글
프로그래머스 - L0 배열의길이에따라다른연산하기 (0) | 2023.12.11 |
---|---|
프로그래머스 - L0 뒤에서5등까지 (0) | 2023.12.11 |
프로그래머스 - L0 접미사인지확인하기 (1) | 2023.12.08 |
프로그래머스 - L0 조건에맞게수열변환하기1 (1) | 2023.12.08 |
프로그래머스 - L0 문자열정수의합 // String.chars() (0) | 2023.12.07 |