146. 문자열 뒤집기

김해준's avatar
Dec 29, 2025
146. 문자열 뒤집기

사용언어 : Java

문제
notion image
풀이
/* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 P r o g r a 2 1 S r e m m 3 // 인덱스(0부터 시작하는) s = 6 / e = 12 0 1 2 3 4 5 12 11 10 9 8 7 6 13 P r o g r a m m e r S 1 2 3 */ class Solution { public String solution(String my_string, int s, int e) { int max = my_string.length(); int current = 0; int index = e; String answer = ""; while(current < max) { if(current >=s && current <= e) { answer += my_string.charAt(index); index--; } else { answer += my_string.charAt(current); } current++; } return answer; } }
notion image
Share article