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

Commit 4e64eea

Browse files
committed
Add solution #3079
1 parent a744493 commit 4e64eea

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,7 @@
21602160
3074|[Apple Redistribution into Boxes](./solutions/3074-apple-redistribution-into-boxes.js)|Easy|
21612161
3075|[Maximize Happiness of Selected Children](./solutions/3075-maximize-happiness-of-selected-children.js)|Medium|
21622162
3076|[Shortest Uncommon Substring in an Array](./solutions/3076-shortest-uncommon-substring-in-an-array.js)|Medium|
2163+
3079|[Find the Sum of Encrypted Integers](./solutions/3079-find-the-sum-of-encrypted-integers.js)|Easy|
21632164
3105|[Longest Strictly Increasing or Strictly Decreasing Subarray](./solutions/3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js)|Easy|
21642165
3108|[Minimum Cost Walk in Weighted Graph](./solutions/3108-minimum-cost-walk-in-weighted-graph.js)|Hard|
21652166
3110|[Score of a String](./solutions/3110-score-of-a-string.js)|Easy|
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* 3079. Find the Sum of Encrypted Integers
3+
* https://leetcode.com/problems/find-the-sum-of-encrypted-integers/
4+
* Difficulty: Easy
5+
*
6+
* You are given an integer array nums containing positive integers. We define a function
7+
* encrypt such that encrypt(x) replaces every digit in x with the largest digit in x.
8+
* For example, encrypt(523) = 555 and encrypt(213) = 333.
9+
*
10+
* Return the sum of encrypted elements.
11+
*/
12+
13+
/**
14+
* @param {number[]} nums
15+
* @return {number}
16+
*/
17+
var sumOfEncryptedInt = function(nums) {
18+
let result = 0;
19+
20+
for (const num of nums) {
21+
let maxDigit = 0;
22+
let temp = num;
23+
let digitCount = 0;
24+
25+
while (temp > 0) {
26+
maxDigit = Math.max(maxDigit, temp % 10);
27+
temp = Math.floor(temp / 10);
28+
digitCount++;
29+
}
30+
31+
let encrypted = 0;
32+
while (digitCount > 0) {
33+
encrypted = encrypted * 10 + maxDigit;
34+
digitCount--;
35+
}
36+
37+
result += encrypted;
38+
}
39+
40+
return result;
41+
};

0 commit comments

Comments
 (0)