Skip to content

Commit a9b314e

Browse files
add 3079
1 parent 6a917b3 commit a9b314e

File tree

3 files changed

+58
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src

3 files changed

+58
-0
lines changed

Diff for: paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
| 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3095.java) | | Easy |
5353
| 3090 | [Maximum Length Substring With Two Occurrences](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3090.java) | | Easy |
5454
| 3083 | [Existence of a Substring in a String and Its Reverse](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3083.java) | | Easy |
55+
| 3079 | [Find the Sum of Encrypted Integers](https://leetcode.com/problems/find-the-sum-of-encrypted-integers/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3079.java) | | Easy |
5556
| 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3074.java) | | Easy |
5657
| 3062 | [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3062.java) | | Easy |
5758
| 3046 | [Split the Array](https://leetcode.com/problems/split-the-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3046.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
public class _3079 {
4+
public static class Solution1 {
5+
public int sumOfEncryptedInt(int[] nums) {
6+
int sum = 0;
7+
for (int num : nums) {
8+
sum += encrypt(num);
9+
}
10+
return sum;
11+
}
12+
13+
private int encrypt(int num) {
14+
int max = 0;
15+
int digits = 0;
16+
while (num != 0) {
17+
max = Math.max(max, num % 10);
18+
num /= 10;
19+
digits++;
20+
}
21+
int ans = 0;
22+
int base = 1;
23+
while (digits > 0) {
24+
ans += base * max;
25+
digits--;
26+
base *= 10;
27+
}
28+
return ans;
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder.fourththousand;
2+
3+
import com.fishercoder.solutions.fourththousand._3079;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _3079Test {
10+
private static _3079.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _3079.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(6, solution1.sumOfEncryptedInt(new int[]{1, 2, 3}));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(66, solution1.sumOfEncryptedInt(new int[]{10, 21, 31}));
25+
}
26+
}

0 commit comments

Comments
 (0)