Algorithm : Programmers - 가운데 글자 가져오기

코일·2021년 12월 28일
0

algorithm

목록 보기
24/37
post-thumbnail

👉 문제

🤔생각해보기

1) 반으로 나누자
2) 짝수일때와 홀수일때를 구분하자

👉 해결

def solution(s):
    if len(s) % 2 == 0:
        answer = int(len(s)/2)
        return str(s[answer-1]+s[answer])

    if len(s) % 2 == 1:
        answer = int(len(s)/2)
        return str(s[answer])
profile
How do you get what you want?🤔🤔

0개의 댓글