Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1bbe09c

Browse files
add 1085
1 parent 0d276fd commit 1bbe09c

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Your ideas/fixes/algorithms are more than welcome!
4444
|1170|[Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1170.java) | | | |Easy||
4545
|1119|[Remove Vowels from a String](https://leetcode.com/problems/remove-vowels-from-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1119.java) | | | [:tv:](https://www.youtube.com/watch?v=6KCBrIWEauw)|Easy||
4646
|1089|[Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1089.java) | O(n^2) | O(1) | |Easy||
47+
|1085|[Sum of Digits in the Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1085.java) | | | |Easy||
4748
|1079|[Letter Tile Possibilities](https://leetcode.com/problems/letter-tile-possibilities/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1079.java) | O(1) | O(1) | |Medium||
4849
|1078|[Occurrences After Bigram](https://leetcode.com/problems/occurrences-after-bigram/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1078.java) | O(n) | O(1) | |Easy||
4950
|1071|[Greatest Common Divisor of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1071.java) | O(m*n) | O(1) | |Easy||
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 1085. Sum of Digits in the Minimum Number
5+
*
6+
* Given an array A of positive integers, let S be the sum of the digits of the minimal element of A.
7+
* Return 0 if S is odd, otherwise return 1.
8+
*
9+
* Example 1:
10+
* Input: [34,23,1,24,75,33,54,8]
11+
* Output: 0
12+
* Explanation:
13+
* The minimal element is 1, and the sum of those digits is S = 1 which is odd, so the answer is 0.
14+
*
15+
* Example 2:
16+
* Input: [99,77,33,66,55]
17+
* Output: 1
18+
* Explanation:
19+
* The minimal element is 33, and the sum of those digits is S = 3 + 3 = 6 which is even, so the answer is 1.
20+
*
21+
* Note:
22+
* 1 <= A.length <= 100
23+
* 1 <= A[i].length <= 100
24+
* */
25+
public class _1085 {
26+
public static class Solution1 {
27+
public int sumOfDigits(int[] A) {
28+
int smallestNumber = A[0];
29+
for (int i = 1; i < A.length; i++) {
30+
smallestNumber = Math.min(smallestNumber, A[i]);
31+
}
32+
int sum = 0;
33+
while (smallestNumber > 0) {
34+
sum += smallestNumber % 10;
35+
smallestNumber /= 10;
36+
}
37+
return sum % 2 == 0 ? 1 : 0;
38+
}
39+
}
40+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1085;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1085Test {
10+
private static _1085.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1085.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(0, solution1.sumOfDigits(new int[]{34, 23, 1, 24, 75, 33, 54, 8}));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(1, solution1.sumOfDigits(new int[]{99, 77, 33, 66, 55}));
25+
}
26+
}

0 commit comments

Comments
 (0)