Last active
May 1, 2020 06:42
-
-
Save DongguemYoo/1aabf5c78118ccae09bad4636c3cb16d to your computer and use it in GitHub Desktop.
코딩테스트 연습 문자열 내림차순으로 배치하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//검색한것 | |
//c# 문자열 정렬 | |
using System.Linq; | |
using System; | |
public class Solution { | |
public string solution(string s) { | |
return new String(s.ToCharArray().OrderByDescending(x => x).ToArray()); | |
CharArray로 자른다음 내림차순으로 정렬한 것을 string으로 변환 | |
} | |
} | |
///제일 직관적인 방식 | |
public class Solution { | |
public string solution(string s) { | |
string answer = ""; | |
char[] a = s.ToCharArray(); //char[] a에 스트링을 charArray로 잘라서 넣는다 | |
System.Array.Sort(a); //오름차순으로 정렬한다. | |
System.Array.Reverse(a);//뒤집는다 | |
answer = new string(a);//스트링에 | |
return answer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment