博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[leetcode] Happy Number
阅读量:4697 次
发布时间:2019-06-09

本文共 731 字,大约阅读时间需要 2 分钟。

Happy Number

Write an algorithm to determine if a number is "happy".

A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.

Example: 19 is a happy number

  • 12 + 92 = 82
  • 82 + 22 = 68
  • 62 + 82 = 100
  • 12 + 02 + 02 = 1
 
Credits:
Special thanks to   and   for adding this problem and creating all test cases.
 
const int SIZE = 1000;class Solution{private:  bool isExist(int n)  {    for(int i=0; i

 

转载于:https://www.cnblogs.com/lxd2502/p/4479646.html

你可能感兴趣的文章
PHP 自动加载类 __autoload() 方法
查看>>
JDK中的Timer和TimerTask详解(zhuan)
查看>>
【python练习】ATM&购物商城程序
查看>>
nginx 日志问题(\x22)
查看>>
装饰器、迭代器、生成器
查看>>
类对象作为类成员
查看>>
面向对象和面向过程的区别及优劣对比详解
查看>>
const与指针
查看>>
thsi指针的一些用法及作用
查看>>
c++友元
查看>>
c++运算符重载
查看>>
一元运算符重载
查看>>
Windows 远程栈溢出挖掘
查看>>
(网页)the server responded with a status of 403 (Forbidden)
查看>>
葡萄城报表介绍:Java 报表
查看>>
android 通知消息一
查看>>
UNET学习笔记2 - 高级API(HLAPI)
查看>>
腾讯编程马拉松2012第一题
查看>>
Day18
查看>>
Web Service数据源
查看>>