File tree 2 files changed +38
-1
lines changed 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,273 LeetCode solutions in JavaScript
1
+ # 1,274 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1060
1060
1387|[ Sort Integers by The Power Value] ( ./solutions/1387-sort-integers-by-the-power-value.js ) |Medium|
1061
1061
1388|[ Pizza With 3n Slices] ( ./solutions/1388-pizza-with-3n-slices.js ) |Hard|
1062
1062
1389|[ Create Target Array in the Given Order] ( ./solutions/1389-create-target-array-in-the-given-order.js ) |Easy|
1063
+ 1390|[ Four Divisors] ( ./solutions/1390-four-divisors.js ) |Medium|
1063
1064
1400|[ Construct K Palindrome Strings] ( ./solutions/1400-construct-k-palindrome-strings.js ) |Medium|
1064
1065
1402|[ Reducing Dishes] ( ./solutions/1402-reducing-dishes.js ) |Hard|
1065
1066
1408|[ String Matching in an Array] ( ./solutions/1408-string-matching-in-an-array.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1390. Four Divisors
3
+ * https://leetcode.com/problems/four-divisors/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an integer array nums, return the sum of divisors of the integers in that array
7
+ * that have exactly four divisors. If there is no such integer in the array, return 0.
8
+ */
9
+
10
+ /**
11
+ * @param {number[] } nums
12
+ * @return {number }
13
+ */
14
+ var sumFourDivisors = function ( nums ) {
15
+ function countDivisors ( num ) {
16
+ const divisors = new Set ( ) ;
17
+ for ( let i = 1 ; i * i <= num ; i ++ ) {
18
+ if ( num % i === 0 ) {
19
+ divisors . add ( i ) ;
20
+ divisors . add ( num / i ) ;
21
+ }
22
+ }
23
+ return divisors ;
24
+ }
25
+
26
+ let result = 0 ;
27
+ for ( const num of nums ) {
28
+ const divisors = countDivisors ( num ) ;
29
+ if ( divisors . size === 4 ) {
30
+ const sum = [ ...divisors ] . reduce ( ( acc , val ) => acc + val , 0 ) ;
31
+ result += sum ;
32
+ }
33
+ }
34
+
35
+ return result ;
36
+ } ;
You can’t perform that action at this time.
0 commit comments