File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 2160
2160
3074|[ Apple Redistribution into Boxes] ( ./solutions/3074-apple-redistribution-into-boxes.js ) |Easy|
2161
2161
3075|[ Maximize Happiness of Selected Children] ( ./solutions/3075-maximize-happiness-of-selected-children.js ) |Medium|
2162
2162
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|
2163
2164
3105|[ Longest Strictly Increasing or Strictly Decreasing Subarray] ( ./solutions/3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js ) |Easy|
2164
2165
3108|[ Minimum Cost Walk in Weighted Graph] ( ./solutions/3108-minimum-cost-walk-in-weighted-graph.js ) |Hard|
2165
2166
3110|[ Score of a String] ( ./solutions/3110-score-of-a-string.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments