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;
}
'코딩테스트 > LV. 0' 카테고리의 다른 글
LV. 0 :: 편지 (0) | 2023.01.21 |
---|---|
LV. 0 :: 특정 문자 제거하기 (0) | 2023.01.20 |
LV. 0 :: 외계행성의 나이 (0) | 2023.01.20 |
LV. 0 :: 자릿수 더하기 (0) | 2023.01.20 |
LV. 0 :: 주사위의 개수 (0) | 2023.01.20 |
댓글