C++:: 프로그래머스 < 가운데 글자 가져오기 >

jahlee·2023년 8월 15일
0

프로그래머스_Lv.1

목록 보기
74/75
post-thumbnail

짝수 홀수 일때의 조건에 맞춰 가운데 글자를 리턴해주면된다.

#include <string>
#include <vector>

using namespace std;

string solution(string s) {
    if (s.size() % 2) return s.substr(s.size()/2,1);
    return s.substr(s.size()/2-1,2);
}

0개의 댓글