https://programmers.co.kr/learn/courses/30/lessons/12915
< ๋ฌธ์์ด ๋ด ๋ง์๋๋ก ์ ๋ ฌํ๊ธฐ >
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import java.util.Arrays;
class Solution {
public String[] solution(String[] strings, int n) {
String temp ;
int cnt=0;
int jungbok=0;
int jung=0;
int cnt1=0;
for(int i =0; i<strings.length-1; i++){
for(int j=0; j<strings.length-1; j++){
if(strings[j].charAt(n) > strings[j+1].charAt(n)){
temp = strings[j];
strings[j]=strings[j+1];
strings[j+1]=temp;
cnt++;
}
if(strings[j].charAt(n) == strings[j+1].charAt(n)){
jungbok++;
jung=j;
}
}if(cnt==0)
break;
}
//์ค๋ณต์ด ์์๊ฒฝ์ฐ
if(jungbok>0){
for(int i =jung; i<strings.length-1; i++){
for(int j=jung; j<strings.length-1; j++){
if(strings[j].charAt(n+1) > strings[j+1].charAt(n+1)){
temp = strings[j];
strings[j]=strings[j+1];
strings[j+1]=temp;
cnt1++;
}
} if(cnt1==0)
break;
}
}
return strings;
}
}
|
cs |
'JAVA > ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java / LEVEL 1] x๋งํผ ๊ฐ๊ฒฉ์ด ์๋ n๊ฐ์ ์ซ์ /programmers/ (0) | 2020.04.08 |
---|---|
[ Java / Level1 ] ์๋ฆฟ์ ๋ํ๊ธฐ /programmers (0) | 2020.02.26 |
๋๋์ด ๋จ์ด์ง๋ ์ซ์ ๋ฐฐ์ด/level1/java/ํ๋ก๊ทธ๋๋จธ์ค (0) | 2020.02.18 |
๋ฌธ์์ด ๋ด๋ฆผ์ฐจ์์ผ๋ก ๋ฐฐ์นํ๊ธฐ/java/level1/programmers (0) | 2020.02.17 |
์์ ์ํธ/ํ๋ก๊ทธ๋๋จธ์ค/level1 (0) | 2020.02.12 |