문제 설명
문자열 str1, str2가 매개변수로 주어집니다. str1 안에 str2가 있다면 1을 없다면 2를 return하도록 solution 함수를 완성해주세요.
입출력 예
나의 풀이 (.contains())
class Solution {
public int solution(String str1, String str2) {
int answer = 2;
if(str1.contains(str2)){
answer = 1;
}
return answer;
}
}
참고 풀이 (.indexOf())
class Solution {
public int solution(String str1, String str2) {
int answer = 0;
if(str1.indexOf(str2) != -1){
answer = 1;
}
else answer =2;
return answer;
}
}
나의 풀이 (.includes())
function solution(str1, str2) {
var answer = 2;
if(str1.includes(str2)){
answer = 1
}
return answer;
}
참고 풀이 1 (.split())
function solution(str1, str2) {
return str1.split(str2).length > 1 ? 1 : 2
}
참고 풀이 2 (.indexOf())
function solution(str1, str2) {
return str1.indexOf(str2) === -1 ? 2 : 1;
}