메모리: 83 MB, 시간: 3.80 ms
코딩테스트 연습 > 코딩테스트 입문
정확성: 100.0
합계: 100.0 / 100.0
영어 대소문자로 이루어진 문자열 my_string이 매개변수로 주어질 때, my_string을 모두 소문자로 바꾸고 알파벳 순서대로 정렬한 문자열을 return 하도록 solution 함수를 완성해보세요.
my_string 길이 < 100| my_string | result |
|---|---|
| "Bcad" | "abcd" |
| "heLLo" | "ehllo" |
| "Python" | "hnopty" |
입출력 예 #1
입출력 예 #2
입출력 예 #3
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges
class Solution {
public String solution(String my_string) {
String[] arr = my_string.toLowerCase().split("");
return Arrays.asList(arr).stream().sorted().collect(Collectors.joining());
}
}
class SolutionTest {
@Test
@DisplayName("Bcad = abcd")
void solution() {
Assertions.assertThat(new Solution().solution("Bcad")).isEqualTo("abcd");
}
@Test
@DisplayName("heLLo = ehllo")
void solution2() {
Assertions.assertThat(new Solution().solution("heLLo")).isEqualTo("ehllo");
}
@Test
@DisplayName("Python = hnopty")
void solution3() {
Assertions.assertThat(new Solution().solution("Python")).isEqualTo("hnopty");
}
}