当前位置:网站首页>20220531 Mathematics: Happy numbers
20220531 Mathematics: Happy numbers
2022-07-03 10:11:00 【Seeyouagain】
Title Description : Write an algorithm to judge a number n Is it a happy number .
Happiness number is defined as : For a positive integer , Replace the number with the sum of the squares of the numbers in each of its positions . Then repeat the process until the number becomes 1, It could be Infinite loop But it doesn't change 1. If this process The result is 1, So this number is the happy number .
If n yes Happy number Just go back to true ; No , Then return to false .
coded :
public static boolean isHappy(int n) {
if (n == 1) {
return true;
} else {
Set<Integer> set = new HashSet<>();
while (n != 1) {
int temp = n, sum = 0;
while (temp >= 10) {
int mod = temp % 10;
temp /= 10;
sum += mod * mod;
}
sum += temp * temp;
if (!set.add(sum)) {
return false;
}
n = sum;
}
}
return true;
}边栏推荐
- 20220610其他:任务调度器
- Serial communication based on 51 single chip microcomputer
- Retinaface: single stage dense face localization in the wild
- CV learning notes - camera model (Euclidean transformation and affine transformation)
- CV learning notes - deep learning
- QT setting suspension button
- Dictionary tree prefix tree trie
- Tensorflow2.0 save model
- 01 business structure of imitation station B project
- (1) What is a lambda expression
猜你喜欢

LeetCode - 460 LFU 缓存(设计 - 哈希表+双向链表 哈希表+平衡二叉树(TreeSet))*

3.1 Monte Carlo Methods & case study: Blackjack of on-Policy Evaluation

One click generate traffic password (exaggerated advertisement title)

QT is a method of batch modifying the style of a certain type of control after naming the control

CV learning notes - edge extraction

3.2 Off-Policy Monte Carlo Methods & case study: Blackjack of off-Policy Evaluation

Anaconda安装包 报错packagesNotFoundError: The following packages are not available from current channels:

Leetcode 300 longest ascending subsequence

Matplotlib drawing

CV learning notes - reasoning and training
随机推荐
1. Finite Markov Decision Process
20220610其他:任务调度器
El table X-axis direction (horizontal) scroll bar slides to the right by default
ADS simulation design of class AB RF power amplifier
Discrete-event system
Connect Alibaba cloud servers in the form of key pairs
20220607其他:两整数之和
LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
The 4G module designed by the charging pile obtains NTP time through mqtt based on 4G network
20220603数学:Pow(x,n)
CV learning notes ransca & image similarity comparison hash
Opencv Harris corner detection
CV learning notes - Stereo Vision (point cloud model, spin image, 3D reconstruction)
My openwrt learning notes (V): choice of openwrt development hardware platform - mt7688
CV learning notes - image filter
Drive and control program of Dianchuan charging board for charging pile design
Opencv notes 17 template matching
Leetcode-100: same tree
is_ power_ of_ 2 judge whether it is a multiple of 2
CV learning notes alexnet