最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 1390. Four Divisors

2023-04-22 16:35 作者:您是打尖兒還是住店呢  | 我要投稿

Given an integer array?nums, return?the sum of divisors of the integers in that array that have exactly four divisors. If there is no such integer in the array, return?0.

?

Example 1:

Input: nums = [21,4,7]

Output: 32

Explanation:?

21 has 4 divisors: 1, 3, 7, 21?

4 has 3 divisors: 1, 2, 4?

7 has 2 divisors: 1, 7?

The answer is the sum of divisors of 21 only.

Example 2:

Input: nums = [21,21]

Output: 64

Example 3:

Input: nums = [1,2,3,4,5]

Output: 0

?

Constraints:

  • 1 <= nums.length <= 104

  • 1 <= nums[i] <= 105

主要就是計算有4個divisor的數(shù)字和,那么我們用set去儲存,遍歷從1到這個數(shù)的平方根,

如果能除盡,那么2個因子都放到set中,最后判斷set的大小為4,則返回每個數(shù)字的和,

如果不是4,返回0;

下面是代碼:

Runtime:?126 ms, faster than?11.96%?of?Java?online submissions for?Four Divisors.

Memory Usage:?43.2 MB, less than?31.58%?of?Java?online submissions for?Four Divisors.


LeetCode 1390. Four Divisors的評論 (共 條)

分享到微博請遵守國家法律
湖州市| 克什克腾旗| 德保县| 阿拉善右旗| 即墨市| 郧西县| 筠连县| 大渡口区| 桦川县| 乌苏市| 永春县| 都昌县| 香港 | 江阴市| 南陵县| 大兴区| 特克斯县| 忻州市| 石屏县| 天峻县| 新邵县| 西青区| 比如县| 大方县| 黔西县| 龙州县| 顺平县| 确山县| 新绛县| 吉水县| 乐亭县| 寻甸| 新干县| 如皋市| 中宁县| 额济纳旗| 集贤县| 县级市| 嫩江县| 原阳县| 井冈山市|