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

Commit c616026

Browse files
authored
Create Find the Sum of Encrypted Integers.java
1 parent c0bd347 commit c616026

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int sumOfEncryptedInt(int[] nums) {
3+
int sum = 0;
4+
for (int num : nums) {
5+
sum += getEncryptedSum(num);
6+
}
7+
return sum;
8+
}
9+
10+
private static int getEncryptedSum(int num) {
11+
int count = 0;
12+
int max = 0;
13+
while (num > 0) {
14+
int digit = num % 10;
15+
num /= 10;
16+
count++;
17+
max = Math.max(digit, max);
18+
}
19+
return Integer.parseInt(String.join("", Collections.nCopies(count, String.valueOf(max))));
20+
}
21+
}

0 commit comments

Comments
 (0)