-
프로그래머스 - 문자열 내 마음대로 정렬하기 [자바]Algorithms/- 프로그래머스 2022. 2. 2. 11:50
- 문제 링크 : 문자열 내 마음대로 정렬하기
정답
import java.util.*; import java.util.stream.*; class Solution { public String[] solution(String[] strings, int n) { return Arrays.stream(strings) .sorted((s1, s2) -> { if(s1.charAt(n) == s2.charAt(n)){ return s1.compareTo(s2); } return s1.charAt(n) - s2.charAt(n); }).toArray(String[]::new); } }
분석
- 단순 중복 조건 정렬 문제여서 stream 연습을 했다.
반응형