forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHW_42885.java
More file actions
22 lines (20 loc) ยท 722 Bytes
/
HW_42885.java
File metadata and controls
22 lines (20 loc) ยท 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// ์๊ฐ ๋ณต์ก๋ : o(n logn)
import java.util.*;
import java.io.*;
// ๋ฌธ์ ๋ชฉํ : ๋ชจ๋ ์ฌ๋์ ๊ตฌ์ถํ๊ธฐ ์ํด ํ์ํ ๊ตฌ๋ช
๋ณดํธ ๊ฐ์์ ์ต์๊ฐ
// ์ต์ ์ ์ ํ : ๊ฐ์ฅ ๋ฌด๊ฑฐ์ด ์ฌ๋์ ๋จผ์ ํ์
class HW_42885 {
public int solution(int[] people, int limit) {
int answer = 0;
Arrays.sort(people); // ์ค๋ฆ์ฐจ์
int left = 0; // ๊ฐ์ฅ ๊ฐ๋ฒผ์ด ์ฌ๋
for(int right = people.length -1; right>= left; right--){
if(people[left] + people[right] <= limit){ // 2๋ช
ํ์ธ ์ ์๋ ๊ฒฝ์ฐ
left++;
}
// 1๋ช
๋ง ํ์ธ ์ ์๋ ๊ฒฝ์ฐ
answer++;
}
return answer;
}
}