Skip to content

Commit 1265d22

Browse files
committed
4. 단어 뒤집기 : rt 와 lt 사용
1 parent f4c782b commit 1265d22

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/ch1/P4.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@ public static void main(String[] args) {
1515
private static String[] solution(int num, String[] strarr) {
1616

1717
for(int i =0; i<num; i++){
18-
String str = new StringBuilder(strarr[i]).reverse().toString();
19-
strarr[i] = str;
18+
char [] arr = strarr[i].toCharArray();
19+
int lt =0;
20+
int rt = arr.length-1;
21+
while (lt<rt){
22+
char tmp = arr[lt];
23+
arr[lt] = arr[rt];
24+
arr[rt] = tmp;
25+
lt++;
26+
rt--;
27+
}
28+
strarr[i] = String.valueOf(arr);
2029
}
2130
return strarr;
2231
}

0 commit comments

Comments
 (0)