티스토리 뷰

 

 

💡 나의 풀이

중요한 점은 문자열의 인덱스 순서가 아니라 단어의 공백을 기준으로 짝/홀을 구분하여 대문자, 소문자로 바꾸는 것이다.

채점 결과
정확성: 100.0
합계: 100.0 / 100.0

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
class Solution {
  public String solution(String s) {
      String answer = "";
      
      String str[] = s.split("");
      String space = " ";
      int cnt = 0;
      
      for(int i = 0; i < str.length; i++){
          if(str[i].equals(space)){
             cnt = 0;
          }else{
             if(cnt % 2 == 0){
                cnt++;
                str[i] = str[i].toUpperCase();
             }else{
                 cnt++;
                 str[i] = str[i].toLowerCase();
             }
          }
          answer += str[i];
      }
      
      System.out.println(answer);
      
      return answer;
  }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
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 31