C# 알고리즘 코드카타

47. 문자열 내 마음대로 정렬하기

잼잼재미 2023. 11. 29. 10:09

 

using System.Linq;

public class Solution {
    public string[] solution(string[] strings, int n) {               
        
        string[] strAnswer = strings.OrderBy(c => c).ToArray();
        strAnswer = strAnswer.OrderBy(c => c[n]).ToArray();

        return strAnswer;
    }
}

* OrederBy 사용

 

https://kkln2486.tistory.com/139

 

OrderBy

OrderBy LINQ에서 추출된 데이터를 오름차순으로 정렬하는 메서드 데이터를 변경하는 것이 아니라 데이터의 순서만 변경 public class Student { public string name; public int score; public int spendTime; } public static

kkln2486.tistory.com

 

'C# 알고리즘 코드카타' 카테고리의 다른 글

49. 두 개 뽑아서 더하기  (0) 2023.12.05
48. K번째수  (1) 2023.12.04
46. 숫자 문자열과 영단어  (1) 2023.11.28
45. 시저 암호  (0) 2023.11.27
44. 최소직사각형  (0) 2023.11.24