728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/12915
코딩테스트 연습 - 문자열 내 마음대로 정렬하기
문자열로 구성된 리스트 strings와, 정수 n이 주어졌을 때, 각 문자열의 인덱스 n번째 글자를 기준으로 오름차순 정렬하려 합니다. 예를 들어 strings가 ["sun", "bed", "car"]이고 n이 1이면 각 단어의 인덱
programmers.co.kr
using System.Linq;
public class Solution {
public string[] solution(string[] strings, int n) {
string[] answer = new string[] {};
answer = strings.OrderBy(x => x).OrderBy(x => x[n]).ToArray();
return answer;
}
}
오름차순으로 정렬하고 index에 맞게 한번 더 정렬
https://docs.microsoft.com/ko-kr/dotnet/api/system.linq.enumerable.orderby?view=net-5.0
Enumerable.OrderBy 메서드 (System.Linq)
시퀀스의 요소를 오름차순으로 정렬합니다.Sorts the elements of a sequence in ascending order.
docs.microsoft.com
반응형
'프로그래머스_C# > Level_1' 카테고리의 다른 글
[프로그래머스 C#] 가운데 글자 가져오기 (0) | 2021.09.02 |
---|---|
[프로그래머스 C#] 두 정수 사이의 합 (0) | 2021.09.02 |
[프로그래머스 C#] 나누어 떨어지는 숫자 배열 (0) | 2021.09.01 |
[프로그래머스 C#] 문자열 다루기 기본 (0) | 2021.08.31 |
[프로그래머스 C#] 문자열 내림차순으로 배치하기 (0) | 2021.08.31 |