https://programmers.co.kr/learn/courses/30/lessons/12917
<๋ฌธ์์ด ๋ด๋ฆผ์ฐจ์์ผ๋ก ๋ฐฐ์นํ๊ธฐ>
โ ์ฒ์ ํผ ํ์ด (ํจ์ ์์ด ํ๊ธฐ)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import java.util.Arrays;
class Solution {
public String solution(String s) {
String answer = "";
char[] a= new char [s.length()];
//๋ฌธ์์ด charAt์ผ๋ก char๋ฐฐ์ด์ ๋ด๊ธฐ
for(int i=0; i<s.length(); i++){
a[i]=s.charAt(i);
}
//์ ๋ ฌ
Arrays.sort(a);
//๋ฐ๋๋ก ๋ํด์ฃผ๊ธฐ
for(int i=s.length()-1; i>=0; i--){
answer+=a[i];
}
return answer;
}
}
|
cs |
โ ์ฐธ๊ณ ํ ํ์ด
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import java.util.Arrays;
public class ReverseStr {
public String reverseStr(String str){
char[] sol = str.toCharArray();
Arrays.sort(sol);
return new StringBuilder(new String(sol)).reverse().toString();
}
// ์๋๋ ํ
์คํธ๋ก ์ถ๋ ฅํด ๋ณด๊ธฐ ์ํ ์ฝ๋์
๋๋ค.
public static void main(String[] args) {
ReverseStr rs = new ReverseStr();
System.out.println( rs.reverseStr("Zbcdefg") );
}
}
|
cs |
'JAVA > ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฌธ์์ด ๋ด ๋ง์๋๋ก ์ ๋ ฌํ๊ธฐ /ํ๋ก๊ทธ๋๋จธ์ค/ java (0) | 2020.02.23 |
---|---|
๋๋์ด ๋จ์ด์ง๋ ์ซ์ ๋ฐฐ์ด/level1/java/ํ๋ก๊ทธ๋๋จธ์ค (0) | 2020.02.18 |
์์ ์ํธ/ํ๋ก๊ทธ๋๋จธ์ค/level1 (0) | 2020.02.12 |
K๋ฒ์งธ์/programmers/level1/java/sort()/copyOfRange() (0) | 2020.02.11 |
ํ๋ ฌ ๋ง์ (0) | 2020.02.10 |