Skip to content

Commit f104be6

Browse files
Create _881.java (fishercoder1534#147)
* Create _881.java * Update _881.java please check once * Add files via upload * Delete 1961. Check If String Is a Prefix of Array.java * Add files via upload * 316 has difficulty level: Medium
1 parent 9d648a9 commit f104be6

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ _If you like this project, please leave me a star._ ★
10341034
| 319 |[Bulb Switcher](https://leetcode.com/problems/bulb-switcher/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_319.java) | |Medium| Brainteaser
10351035
| 318 |[Maximum Product of Word Lengths](https://leetcode.com/problems/maximum-product-of-word-lengths/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_318.java) | |Medium|
10361036
| 317 |[Shortest Distance from All Buildings](https://leetcode.com/problems/shortest-distance-from-all-buildings/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_317.java) | |Hard|
1037-
| 316 |[Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_316.java) | |Hard| Stack, Recursion, Greedy
1037+
| 316 |[Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_316.java) | |Medium| Stack, Recursion, Greedy
10381038
| 315 |[Count of Smaller Numbers After Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_315.java) | |Hard| Tree
10391039
| 314 |[Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_314.java) | |Medium| HashMap, BFS
10401040
| 313 |[Super Ugly Number](https://leetcode.com/problems/super-ugly-number/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_313.java) | |Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1961{
4+
public class Solution1 {
5+
public boolean isPrefixString(String s, String[] words) {
6+
7+
String t="";
8+
int i=0;
9+
10+
while(t.length()<s.length() && i<words.length){
11+
t+=words[i++];
12+
13+
if(t.equals(s))
14+
return true;
15+
}
16+
17+
return false;
18+
19+
}
20+
}
21+
}

src/main/java/com/fishercoder/solutions/_881.java

+24
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,28 @@ public int numRescueBoats(int[] people, int limit) {
5757
return boats;
5858
}
5959
}
60+
61+
public static class Solution2 {
62+
public int numRescueBoats(int[] people, int limit) {
63+
Arrays.sort(people);
64+
int end = people.length - 1;
65+
int start = 0;
66+
int boatcount = 0;
67+
while (end >= start) {
68+
if (people[end] == limit) {
69+
end--;
70+
boatcount++;
71+
} else if (people[end] + people[start] <= limit) {
72+
start++;
73+
end--;
74+
boatcount++;
75+
} else {
76+
end--;
77+
boatcount++;
78+
}
79+
}
80+
return boatcount;
81+
}
82+
}
83+
6084
}

0 commit comments

Comments
 (0)