-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[level 1] Title: 가운데 글자 가져오기, Time: 11.03 ms, Memory: 78.1 MB -Baekjo…
…onHub
- Loading branch information
1 parent
4a5156d
commit 2e136f0
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# [level 1] 가운데 글자 가져오기 - 12903 | ||
|
||
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/12903#) | ||
|
||
### 성능 요약 | ||
|
||
메모리: 78.1 MB, 시간: 11.03 ms | ||
|
||
### 구분 | ||
|
||
코딩테스트 연습 > 연습문제 | ||
|
||
### 채점결과 | ||
|
||
Empty | ||
|
||
### 문제 설명 | ||
|
||
<p>단어 s의 가운데 글자를 반환하는 함수, solution을 만들어 보세요. 단어의 길이가 짝수라면 가운데 두글자를 반환하면 됩니다.</p> | ||
|
||
<h6>재한사항</h6> | ||
|
||
<ul> | ||
<li>s는 길이가 1 이상, 100이하인 스트링입니다.</li> | ||
</ul> | ||
|
||
<h5>입출력 예</h5> | ||
<table class="table"> | ||
<thead><tr> | ||
<th>s</th> | ||
<th>return</th> | ||
</tr> | ||
</thead> | ||
<tbody><tr> | ||
<td>"abcde"</td> | ||
<td>"c"</td> | ||
</tr> | ||
<tr> | ||
<td>"qwer"</td> | ||
<td>"we"</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
> 출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Solution { | ||
public String solution(String s) { | ||
String answer = ""; | ||
int sLength = s.length(); | ||
|
||
// 1. 단어 s 문자열의 길이가 짝수일 경우 | ||
if (sLength % 2 == 0) { | ||
int div = sLength / 2; | ||
answer += s.charAt(div - 1); | ||
answer += s.charAt(div); | ||
} | ||
// 2. 단어 s 문자열의 길이가 홀수일 경우 | ||
else { | ||
int div = sLength / 2; | ||
answer += s.charAt(div); | ||
} | ||
|
||
return answer; | ||
} | ||
} |