반응형
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
- docker remove
- docker 삭제
- m1 docker
- codeup 1020 java
- 나누어 떨어지는 숫자 배열 python
- 가운데 글자 가져오기 java
- 트리의 지름 java
- 코드업 1020 자바
- docker 완전 삭제
- 프로그래머스 가운데 글자 가져오기 파이썬
- 가운데 글자 가져오기 자바
- codeup 1020 자바
- 최단 경로 알고리즘
- 프로그래머스 가운데 글자 가져오기 python
- 최소 스패닝 트리
- 트리의 지름 자바
- 나누어 떨어지는 숫자 배열 java
- 프로그래머스 나누어 떨어지는 숫자 배열 파이썬
- 빅데이터분석기사
- 코드업 1020 java
- 프로그래머스 나누어 떨어지는 숫자 배열 자바
- m1 docker install
- 가운데 글자 가져오기 python
- 최소 스패닝 트리 자바
- 프로그래머스 가운데 글자 가져오기 자바
- 청년 AI Big Data 아카데미 13기
- 빅분기실기
- 가운데 글자 가져오기 파이썬
- 청년 Ai Big Data 아카데미
- 핸즈온 머신러닝
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]) |
반응형
Comments