-
[프로그래머스] 접미사 배열알고리즘 노트 2023. 10. 18. 10:38
지문의 이해가 오히려 더 어려웠던 것 같습니다..
위 내용은 결국 문자열을 하나씩 잘라 알파벳 순서대로 정렬을 해서 반환하면 되는 문제였습니다.
[문제풀이]
1. IntStream의 range() 메소드로 loop문을 구현합니다. 길이는 my_string의 length()까지 입니다.
2. mapToObj() 메소드를 통해 잘라낸 String을 구합니다. 여기서 ::는 substring의 인자를 하나만 받는 메소드가 하나밖에 없을 경우 사용 가능합니다. 따라서 ::substring을 활용하면 .substring(i)로 치환되어 사용됩니다.
3. sorted() 메소드를 통해 잘라낸 문자열을 알파벳 순서로 정렬합니다.
4. toArray() 메소드를 통해 String 배열을 반환합니다. 여기서는 새로운 String 배열을 만들고 거기에 초기화 값을 앞서 잘라낸 문자열들로 채워주는 역할을 합니다.
'알고리즘 노트' 카테고리의 다른 글
[프로그래머스] 문자열 뒤집기 (0) 2023.10.19 [프로그래머스] 접미사인지 확인하기 (0) 2023.10.18 [프로그래머스] 문자열의 뒤의 n글자 (0) 2023.10.18 [프로그래머스] 부분 문자열 이어 붙여 문자열 만들기 (0) 2023.10.18 [프로그래머스] 배열 만들기 5 (0) 2023.10.18