programmers_JadenCase 문자열 만들기_java
2023. 2. 27. 10:06ㆍAlgorithm/Programmers
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/12951#
import java.util.*;
import java.util.regex.Pattern;
class Solution {
public String solution(String s) {
String answer = "";
StringBuilder sb = new StringBuilder();
s = s.toLowerCase();
char[] sArr = s.toCharArray();
int size = sArr.length;
for(int i = 0; i< size;){
if(sArr[i] == ' '){
while(i < size && sArr[i] == ' '){
sb.append(' ');
i++;
}
}
if(i < size && sArr[i] >= 'a' && sArr[i] <= 'z' ){
sb.append((char)(sArr[i] - 32));
i++;
}
while(i < size && sArr[i] != ' '){
sb.append(sArr[i]);
i++;
}
}
answer = sb.toString();
return answer;
}
}
'Algorithm > Programmers' 카테고리의 다른 글
programmers_최솟값 만들기_java (0) | 2023.02.27 |
---|---|
programmers_올바른 괄호_java (0) | 2023.02.27 |
programmers_최댓값과 최솟값_java (0) | 2023.02.24 |
Programmers_이중우선순위큐_java (0) | 2023.02.23 |
Programmers_정수 삼각형_java (0) | 2023.02.22 |