-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx05_04_timeCheck.java
More file actions
48 lines (35 loc) ยท 1.18 KB
/
Copy pathEx05_04_timeCheck.java
File metadata and controls
48 lines (35 loc) ยท 1.18 KB
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
package study.inflearn.lecture02.section05;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* ๊ฝ์ด ํผ๋ ์ต๋จ์๊ฐ - greedy
* ๊ฐ์ฌ๋ ํด๋ฒ ๋ฃ๊ณ ์ฌ๋์
*/
public class Ex05_04_timeCheck {
public static void listChk(int n) {
long start = System.currentTimeMillis();
List<int[]> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(new int[]{i, i});
}
Collections.sort(list, (a,b) -> b[1] - a[1]); // note Collectinos.sort() ์๊ฐ๋ณต์ก๋ ํ๊ท /์ต์
O(nlogn)
System.out.println("listChk = " + (System.currentTimeMillis() - start));
}
public static void arrayChk(int n) {
long start = System.currentTimeMillis();
Integer[][] array = new Integer[n][2];
for (int i = 0; i < n; i++) {
array[i][0] = i;
array[i][1] = i;
}
Arrays.sort(array, (a,b) -> b[1] - a[1]);
System.out.println("arrayChk = " + (System.currentTimeMillis() - start));
}
public static void main(String[] args){
int n = 50_000_000;
listChk(n);
arrayChk(n);
}
}