반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- codeup 1020 자바
- 최소 스패닝 트리
- 가운데 글자 가져오기 java
- 프로그래머스 나누어 떨어지는 숫자 배열 파이썬
- 가운데 글자 가져오기 파이썬
- codeup 1020 java
- 최소 스패닝 트리 자바
- docker 삭제
- 빅분기실기
- m1 docker
- 트리의 지름 java
- docker 완전 삭제
- m1 docker install
- 청년 AI Big Data 아카데미 13기
- 프로그래머스 가운데 글자 가져오기 python
- 코드업 1020 자바
- 트리의 지름 자바
- 최단 경로 알고리즘
- 청년 Ai Big Data 아카데미
- 나누어 떨어지는 숫자 배열 java
- 나누어 떨어지는 숫자 배열 python
- docker remove
- 빅데이터분석기사
- 가운데 글자 가져오기 자바
- 코드업 1020 java
- 프로그래머스 가운데 글자 가져오기 파이썬
- 프로그래머스 가운데 글자 가져오기 자바
- 가운데 글자 가져오기 python
- 핸즈온 머신러닝
- 프로그래머스 나누어 떨어지는 숫자 배열 자바
Archives
- Today
- Total
NineTwo meet you
[프로그래머스/파이썬/자바] 가운데 글자 가져오기 본문
반응형
문제 & 제한사항 & 예제
더보기
문제 설명
단어 s의 가운데 글자를 반환하는 함수, solution을 만들어 보세요.
단어의 길이가 짝수라면 가운데 두글자를 반환하면 됩니다.
재한사항
- s는 길이가 1 이상, 100이하인 스트링입니다.
입출력 예
s | return |
"abcde" | "c" |
"qwer" | "we" |
코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public String solution(String s) { | |
String answer = ""; | |
int mid = 0; | |
if(s.length()%2 != 0){ | |
mid = s.length()/2; | |
answer = s.substring(mid, mid+1); | |
}else{ | |
mid = s.length()/2; | |
answer = s.substring(mid-1, mid+1); | |
} | |
return answer; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(s): | |
if len(s)%2 != 0: | |
return(s[int(len(s)/2)]) | |
else: | |
return(s[int(len(s)/2)-1:int(len(s)/2)+1]) |
반응형
'프로그래밍 문제 > 프로그래머스' 카테고리의 다른 글
[프로그래머스/파이썬/자바] 이상한 문자 만들기 (0) | 2020.08.21 |
---|---|
[프로그래머스/파이썬/자바] 나누어 떨어지는 숫자 배열 (0) | 2020.08.21 |
[프로그래머스/파이썬/자바] 두 정수 사이의 합 (0) | 2020.08.21 |
[프로그래머스/파이썬/자바] 같은 숫자는 싫어 (0) | 2020.08.21 |
[프로그래머스/파이썬/자바] 2016년 (0) | 2020.08.21 |