归一数字的定义过程如下: 给定一个正整数,计算它每一位数的平方和生成一个新的数字,重复这个过程,当生成的新数字等于1时,则认定该正整数为归一数字。 输入描述 Int型正整数 输出描述 布尔型truefalse 例子: 82是一个归一数字 82 + 22 = 68 62 + 82 = 100 12 + 02 + 02 = 1
示例1
输入
82
输出
true
加载中...
import java.util.*; public class Solution { /** * 是否归一数字 * @param n int整型 数字 * @return bool布尔型 */ public boolean isHappy (int n) { // write code here } }
class Solution { public: /** * 是否归一数字 * @param n int整型 数字 * @return bool布尔型 */ bool isHappy(int n) { // write code here } };
# # 是否归一数字 # @param n int整型 数字 # @return bool布尔型 # class Solution: def isHappy(self , n ): # write code here
/** * 是否归一数字 * @param n int整型 数字 * @return bool布尔型 */ function isHappy( n ) { // write code here } module.exports = { isHappy : isHappy };
# # 是否归一数字 # @param n int整型 数字 # @return bool布尔型 # class Solution: def isHappy(self , n ): # write code here
package main /** * 是否归一数字 * @param n int整型 数字 * @return bool布尔型 */ func isHappy( n int ) bool { // write code here }
/** * 是否归一数字 * @param n int整型 数字 * @return bool布尔型 */ bool isHappy(int n ) { // write code here }
82
true