Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- ๋น์ผ๊ฐ์ฒด์์ฑ
- mysql
- ์์ดํ 15
- ์์
- builder null
- ์๋ฐ
- ์๋ฐ์ฐ๋ ๋
- ์๋ฐ๋ผ์ด๋ธ์คํฐ๋
- ์๋ฐ์์
- ๋ฐ์ดํฐ๋ฒ ์ด์ค๊ฒฉ๋ฆฌ์์ค
- enum ์์ฑ์ ์ ๊ทผ ์ ํ์
- ์๋ฐ์์์ฐ๋ ๋๋ฅผ ์ฌ์ฉํ๋ ์ด์
- ์ธ๋ฑ์คํ์ค์บ
- InnoDB์ํคํ ์ฒ
- Item6
- item15
- ์๋ผ์คํฑ์์น๋ฉ์ธ์ง์ฉ๋
- SVN
- assert.notnull
- effectiveJava
- index full scan
- ์ดํํฐ๋ธ์๋ฐ
- ์ธ๋ฑ์ค์คํต์ค์บ
- hikari cp ์ค์
- index skip scan
- ์ํฐ๋ ๊ฐ๋ฐ์ํ์ฌ
- mysql์ํคํ ์ฒ
- Hikari Connection Pool
- ์ํฐ๋ ๋ณ์ข ๊ฐ๋ฐ์
- ๋ฐ์ฉ๋ ์ค๊ตญ์ด
Archives
- Today
- Total
โ๐ป๊ธฐ๋กํ๋ ๋ธ๋ก๊ทธ
[์ ๋ ฌ] ๋ฒ๋ธ์ ๋ ฌ ( Bubble Sort ) ๋ณธ๋ฌธ
728x90
๋ฒ๋ธ ์ ๋ ฌ ( Bubble Sort )
๋ฐฐ์ด์์ ๋ ๊ฐ์ ๊ฐ์ ์ก๊ณ ์๋ก ํฌ๊ธฐ๋ฅผ ๋น๊ตํ๋ฉด์ ์์ ๊ฐ์ ์์ผ๋ก ํฐ ๊ฐ์ ๋ค๋ก ํฌ๊ธฐ๋ฅผ ์ ๋ ฌํ๋ ๋ฐฉ๋ฒ
๋ฐฐ์ด์ ์ฒ์๋ถํฐ ๋๊น์ง ์ง๋๋ฉด์ ์ ๋ ฌํ๋ฏ๋ก O(n์ ๊ณฑ)์๊ฐ์ด ์์๋จ
ํ๋ก๊ทธ๋๋จธ์ค ์ ๋ ฌ > k๋ฒ์งธ์
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
for(int i=0; i<commands.length; i++){
int[] temp = commands[i];
int start = temp[0]-1;
int end = temp[1];
List<Integer> arrList = new ArrayList<Integer>();
for(int j=start; j<end; j++){
System.out.println(array[j]);
arrList.add(array[j]);
}
int[] result = new int[arrList.size()];
for(int k=0; k<arrList.size(); k++){
result[k] = arrList.get(k);
}
Arrays.sort(result);
answer[i] = result[temp[2]-1];
}
return answer;
}
}
๋ณด์ถฉ
Arrays.copyOfRange(์๋ณธ ๋ฐฐ์ด, ๋ณต์ฌํ ์์ ์ธ๋ฑ์ค, ๋ณต์ฌํ ๋ง์ง๋ง ์ธ๋ฑ์ค);
์์ ํ์ด๋ฅผ copyOfRange๋ฅผ ์ฌ์ฉํด์ ํ์ํ ๋ฐฐ์ด๋ง ์๋ก ๋ง๋ค ์ ์๋ค.
copyOfRange๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ๋จํด์ง ํ์ด
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
for(int i=0; i<commands.length; i++){
int[] temp = Arrays.copyOfRange(array, commands[i][0]-1, commands[i][1]);
Arrays.sort(temp);
answer[i] = temp[commands[i][2]-1];
}
return answer;
}
}
728x90
๋ฐ์ํ
'์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค - ํด์] Lv2.์์ฅ (0) | 2022.07.26 |
---|---|
leetcode - 217. Contains Duplicate (0) | 2022.01.08 |
ํด์ - Lv1.์์ฃผํ์ง ๋ชปํ ์ ์ (0) | 2020.09.27 |