Gidhub BE Developer

Programmers - 가운데 글자 가져오기

2018-07-22
goodGid

Problem

Problem URL : 가운데 글자 가져오기


[1] Answer Code (18. 07. 22)


// By Gid
string solution(string s) {
    string answer = "";
    int size = s.size();
    if(size & 1){ // Odd
        answer = s[ size / 2];
    }else { // Even
        answer = s[ size / 2 - 1] ;
        answer += s[size/2];
    }
    return answer;
}


// By Other
string solution(string s) {
    string answer = "";

    int len = s.length();
    if (len%2 == 0) {
        answer = s.substr((len/2)-1, 2);
    } else {
        answer = s[len/2];
    }
    return answer;
}



[1] Answer Code (18. 07. 22)

  • Programmers Problem

Comments

Content