-
프로그래머스 - 가운데 글자 가져오기 [자바]Algorithms/- 프로그래머스 2022. 2. 1. 02:29
- 문제 링크 : 가운데 글자 가져오기
정답
class Solution { public String solution(String s) { String answer = ""; int length = s.length(); int index = length / 2; if(length % 2 == 0){ answer = s.substring(index-1, index+1); }else{ answer = String.valueOf(s.charAt(index)); } return answer; } }
분석
- 단순 String 자르기, index 문제
반응형