Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a6cc58

Browse files
authored
added solution for 1283 (fishercoder1534#129)
1 parent59725e6 commit4a6cc58

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ _If you like this project, please leave me a star._ ★
174174
|1289|[Minimum Falling Path Sum II](https://leetcode.com/problems/minimum-falling-path-sum-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1289.java)||Hard|Dynamic Programming|
175175
|1287|[Element Appearing More Than 25% In Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1287.java)|[:tv:](https://youtu.be/G74W8v2yVjY)|Easy||
176176
|1286|[Iterator for Combination](https://leetcode.com/problems/iterator-for-combination/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1286.java)||Medium|Backtracking, Design|
177+
|1283|[Find the Smallest Divisor Given a Threshold](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1283.java)| Medium|
177178
|1282|[Group the People Given the Group Size They Belong To](https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1282.java)|[:tv:](https://www.youtube.com/watch?v=wGgcRCpSAa8)|Medium||
178179
|1281|[Subtract the Product and Sum of Digits of an Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1281.java)||Easy||
179180
|1277|[Count Square Submatrices with All Ones](https://leetcode.com/problems/count-square-submatrices-with-all-ones/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1277.java)||Medium||
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1283 {
4+
publicstaticclassSolution{
5+
privatebooleanisSumLessThanThreshold(intmiddle,int[]nums,intthreshold){
6+
intsum =0;
7+
for(inti =0;i<nums.length;i++){
8+
if(nums[i] %middle ==0)
9+
sum +=nums[i]/middle;
10+
else
11+
sum +=nums[i]/middle +1;
12+
}
13+
returnsum <=threshold;
14+
}
15+
publicintsmallestDivisor(int[]nums,intthreshold) {
16+
17+
intstart =1,result =0;
18+
intend =Integer.MAX_VALUE;
19+
while(start <=end){
20+
intmiddle =start + (end -start)/2;
21+
if(isSumLessThanThreshold(middle,nums,threshold)){
22+
result =middle;
23+
end =middle -1;
24+
}
25+
else{
26+
start =middle +1;
27+
}
28+
}
29+
returnresult;
30+
}
31+
}
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.common.utils.TreeUtils;
4+
importcom.fishercoder.solutions._1283;
5+
importorg.junit.BeforeClass;
6+
importorg.junit.Test;
7+
8+
importjava.util.Arrays;
9+
10+
importstaticjunit.framework.TestCase.assertEquals;
11+
12+
publicclass_1283Test {
13+
privatestatic_1283.Solutionsolution;
14+
privatestaticint[]nums;
15+
privatestaticintthreshold;
16+
@BeforeClass
17+
publicstaticvoidsetup() {
18+
solution =new_1283.Solution();
19+
}
20+
21+
@Test
22+
publicvoidtest1() {
23+
nums =newint []{1,2,5,9};
24+
threshold =6;
25+
assertEquals(5,solution.smallestDivisor(nums,threshold));
26+
}
27+
@Test
28+
publicvoidtest2() {
29+
nums =newint []{2,3,5,7,11};
30+
threshold =11;
31+
assertEquals(3,solution.smallestDivisor(nums,threshold));
32+
}
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp