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

Add solution for 1283#129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fishercoder1534 merged 1 commit intofishercoder1534:masterfromashmichheda:1283
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -173,6 +173,7 @@ _If you like this project, please leave me a star._ ★
|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|
|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||
|1286|[Iterator for Combination](https://leetcode.com/problems/iterator-for-combination/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1286.java) | |Medium|Backtracking, Design|
|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 |
|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||
|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||
|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||
Expand Down
32 changes: 32 additions & 0 deletionssrc/main/java/com/fishercoder/solutions/_1283.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
package com.fishercoder.solutions;

public class _1283 {
public static class Solution{
private boolean isSumLessThanThreshold(int middle, int[] nums, int threshold){
int sum = 0;
for(int i = 0; i<nums.length; i++){
if(nums[i] % middle == 0)
sum += nums[i]/middle;
else
sum += nums[i]/middle + 1;
}
return sum <= threshold;
}
public int smallestDivisor(int[] nums, int threshold) {

int start = 1, result = 0;
int end = Integer.MAX_VALUE;
while(start <= end){
int middle = start + (end - start)/2;
if(isSumLessThanThreshold(middle, nums, threshold)){
result = middle;
end = middle - 1;
}
else{
start = middle + 1;
}
}
return result;
}
}
}
33 changes: 33 additions & 0 deletionssrc/test/java/com/fishercoder/_1283Test.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
package com.fishercoder;

import com.fishercoder.common.utils.TreeUtils;
import com.fishercoder.solutions._1283;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.Arrays;

import static junit.framework.TestCase.assertEquals;

public class _1283Test {
private static _1283.Solution solution;
private static int[] nums;
private static int threshold;
@BeforeClass
public static void setup() {
solution = new _1283.Solution();
}

@Test
public void test1() {
nums = new int []{1,2,5,9};
threshold = 6;
assertEquals(5, solution.smallestDivisor(nums, threshold));
}
@Test
public void test2() {
nums = new int []{2,3,5,7,11};
threshold = 11;
assertEquals(3, solution.smallestDivisor(nums, threshold));
}
}

[8]ページ先頭

©2009-2025 Movatter.jp