코딩테스트/LV. 0
LV. 0 :: 문자열 안에 문자열
KUROMI98
2023. 1. 20. 19:29
https://school.programmers.co.kr/learn/courses/30/lessons/120908
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
function solution(str1, str2) {
var answer = 0;
var index = str1.indexOf(str2);
if (index>=0) {answer=1;}
else answer=2;
return answer;
}
+)230511
const solution = (str1, str2) => {
let index = str1.indexOf(str2);
index != -1 ? index=1 : index=2
return index;
}
230526 python
def solution(str1, str2):
answer = 2
if str2 in str1:
answer = 1
return answer
230915 C++
#include <string>
#include <vector>
using namespace std;
int solution(string str1, string str2) {
int answer = 0;
int index = str1.find(str2);
(index == -1) ? answer = 2 : answer = 1 ;
return answer;
}
- 이렇게 해도 됨
#include <string>
using namespace std;
int solution(string str1, string str2) {
return str1.find(str2) == -1 ? 2 : 1;
}