์ฒด๊ฐ Level : โ
โ โ Review: ๋ฌธ์ ์ ๋ ฌํ๋ ๋ฐฉ๋ฒ |
๐ก๋ฌธ์์ด s์ ๋ํ๋๋ ๋ฌธ์๋ฅผ ํฐ๊ฒ๋ถํฐ ์์ ์์ผ๋ก ์ ๋ ฌํด ์๋ก์ด ๋ฌธ์์ด์ ๋ฆฌํดํ๋ ํจ์, solution์ ์์ฑํด์ฃผ์ธ์. s๋ ์๋ฌธ ๋์๋ฌธ์๋ก๋ง ๊ตฌ์ฑ๋์ด ์์ผ๋ฉฐ, ๋๋ฌธ์๋ ์๋ฌธ์๋ณด๋ค ์์ ๊ฒ์ผ๋ก ๊ฐ์ฃผํฉ๋๋ค.
https://school.programmers.co.kr/learn/courses/30/lessons/12917
๐ฌ StringBuilder // Character ๋ฐฐ์ด ๋ฌธ์์ด๋ก ๋ณํ
๐ฌ Arrays.sort(charObjectArray, Collections.reverseOrder()); // ์ญ์ ์ ๋ ฌ
๐ฌ char[] charArray = lowerStr.toCharArray(); // ๋ฌธ์๋ฐฐ์ด ๋ฌธ์์ด๋ก
import java.util.*;
class Solution {
public String solution(String s) {
String answer = "";
char[] arr = s.toCharArray();
Character[] arr2 = new Character[arr.length];
for (int i = 0; i < arr.length; i++) {
arr2[i] = arr[i];
}
Arrays.sort(arr2 , Collections.reverseOrder());
StringBuilder str = new StringBuilder(arr2.length);
for (Character c : arr2) {
str.append(c);
}
answer = str.toString();
return answer;
}
}