Skip to content

Commit 3cd5bb8

Browse files
committed
leetcode daily
1 parent 3b6a474 commit 3cd5bb8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* FILE: 881.boats_to_save_people.cpp
3+
* @author: Arafat Hasan Jenin <opendoor.arafat[at]gmail[dot]com>
4+
* LINK: https://leetcode.com/problems/boats-to-save-people/
5+
* DATE CREATED: 24-03-22 11:56:36 (+06)
6+
* LAST MODIFIED: 24-03-22 17:42:08 (+06)
7+
* VERDICT: Accepetd
8+
*/
9+
10+
11+
class Solution {
12+
public int numRescueBoats(int[] people, int limit) {
13+
int start = 0, end = people.length - 1, cnt = 0;
14+
Arrays.sort(people);
15+
16+
while(start <= end){
17+
if(people[start] + people[end] <= limit){
18+
start++;
19+
end--;
20+
}else{
21+
end--;
22+
}
23+
cnt++;
24+
}
25+
return cnt;
26+
}
27+
}

0 commit comments

Comments
 (0)