leetcode-202 Happy Number

Windows下TensorRT+YOLOv11部署避坑指南:从CUDA配置到模型加密全流程 本文详细解析了在Windows平台部署YOLOv11与TensorRT的全流程,重点涵盖从CUDA环境配置、工程编译适配到模型加密保护的实战指南。基于wang-xinyu的tensorrtx仓库,提供了详细的版本选择、编译问题修复方案,并深入探讨了如何对TensorRT引擎进行加密,以实现高效且安全的端到端部署。 阅读详情

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

1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1

题意清楚。要注意的是可能陷入无限循环中。因此要注意,记录之前出现的数字,一旦发现重复的,就代表陷入死循环,返回false。
时间8ms。
代码:

class Solution {
public:
    unordered_set<int> hashset;
    bool isHappy(int n) {
        hashset.insert(n);
        int tmp=0;
        while(n > 0)
        {
            int i = n%10;
            n=n/10;
            tmp = tmp + i*i;
        }
        if(1 == tmp)
        return true;
        else
        {
            if(hashset.find(tmp) != hashset.end())
            return false;
            else
            isHappy(tmp);
        }
    }
};
SIwave仿真手册——软件基础(一) 最近在学习SIWAVE,在这里将自己的笔记整理一下,做一个专题。希望对大家有帮助,这个会持续更新的。仅限于软件操作学习,不涉及信号完整性的讨论。 阅读详情

相关推荐

【HCIE】FRR+BFD+OSPF与BGP联动

FRR+BFD+OSPF与BGP联动

Wenrs的博客 2009

[leetcode] 202. Happy Number

Description 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 th...

Learning from the mistakes 289

别再死记硬背了!用Wireshark抓包实战,5分钟搞懂GRE、L2TP、IPsec的区别

本文通过Wireshark抓包实战,详细解析GRE、L2TP和IPsec三大隧道协议的核心差异与应用场景。从报文结构到配置示例,帮助网络工程师快速掌握这些协议的本质,提升VPN部署与故障排查能力。特别适合准备HCIP认证的工程师深化理解。

weixin_30352645的博客 443

[LeetCode 202] Happy Number

题目链接: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 numbe

瓦尔登湖 4161

【测试】echo发送和接收TCP/UDP数据包|shell 发送TCP/UDP数据包

目录 通过/dev/tcp、/dev/udp shell给tcp或udp服务发送16进制报文指令 通过/dev/tcp、/dev/udp (https://blog.csdn.net/u010039418/article/details/86251470) 通过/dev/tcp、/dev/udp可以直接在shell脚本中发起tcp、udp连接,方便又高效,平时用于测试啥的还是挺方便的。 直接发送 格式 /dev/udp/ip/port 比如要向本地10001端口发送数据,可以使用 ec.

我的笔记本 1万+

pytorch转onnx转paddlepaddle

1.pt转onnx 可查看我之前的文章:https://blog.csdn.net/oyjwin/article/details/117778583?spm=1001.2014.3001.5501

oyjwin的博客 1469

LeetCode 202: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

哈哈的个人专栏 2361

AutoJs调用DeepSeek大模型接口实战教程 AutoJs接入DeepSeek、 DeepSeek API调用 、 手机脚本接入大模型

通过这篇文章,我们用 AutoJs 成功接入了 DeepSeek Chat API。使用发送请求在 Header 里正确携带 API Key从里拿到最终返回结果这样一来,你就可以在 AutoJs 里实现一个智能助手脚本,甚至做更复杂的 AI 自动化工具。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 484

Leetcode_202_Happy Number

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/45396585 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 th

皮斯特劳沃 2370

PCL 点到面的ICP算法【2024最新版】

经典的点到面的ICP算法。博客长期更新,本文最新更新时间为:2024年10月18日。

点云侠的博客 36万+

《Python Web项目集锦》-专栏介绍和目录

本专栏专注于Python Web项目,涉及内容包含FastAPI、Django、Flask等,所有项目代码完整且可直接运行。不管是零基础还是有经验的开发,相信都能从本专栏获益。有任何问题欢迎私聊博主,专栏持续更新中...

数据知道的博客 5232

LeetCode202:Happy Number

LeetCode202:Happy Number 一、题目地址:https://leetcode.com/problems/happy-number/ 二、题目描述:    Write an algorithm to determine if a number is "happy".    A happy number is a number defined by the fo

tinyskyye的专栏 333

Apollo Planning2.0决策规划算法代码详细解析 (1):环境搭建

1、官方提供连接:git clone https://github.com/ApolloAuto/application-pnc.git。此外,也更新了dreamview对pnc的支持,使得调试更加方便。apollo开源团队近期更新了planning版本,对代码进行了一定程度上的重构。(2)进入docker,并编译整个工程:./apollo.sh build_dbg。下载项目环境后使用aem进行环境配置;2、有一定基础建议直接拉取最新代码,自己手动进行编译。(1)环境安装: ./dev_start.sh。

自动驾驶Player的博客 1847

LeetCode202 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 s...

zhangjun62的博客 242

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

leetcode 202: Happy Number

Happy Number Total Accepted: 3585 Total Submissions: 10859 Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting wi

西施豆腐渣 8848

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

[LeetCode202] 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

coder 进阶的专栏 1934

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

leetcode 202 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 o

shiter编写程序的艺术 3940

Leetcode 202. Happy Number 快乐数

Leetcode 202. Happy Number 快乐数202. Happy Number 快乐数题目描述示例:解答1代码1解答2代码2 202. Happy Number 快乐数 题目描述 Share Write an algorithm to determine if a number is “happy”. A happy number is a number defined by th...

importsys的博客 740

(LeetCode 202) Happy Number

Q: 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

SuperNova 443

LeetCode 202 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

Yano_nankai的博客 2017

[LeetCode] 202. Happy Number

题目内容 https://leetcode-cn.com/problems/happy-number/ 编写一个算法来判断一个数是不是“快乐数”。 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1。如果可以变为 1,那么这个数就是快乐数。 示例: 输入: 19 输出: tru...

Reyiiiin的深夜一点半 272

Leetcode 202 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

无名山丘,崛起成峰 899

202. Happy Number Leetcode Python

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

hyperbolechi的专栏 1272

[LeetCode]202.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

SmartSi 2837

Leetcode 202 Happy Number 弗洛伊德判环解循环

今天先谈下弗洛伊德判环,弗洛伊德判环原来是在一个圈内有两人跑步,同时起跑,一人的速度是另一人的两倍,则那个人能在下一圈追上另一个人,弗洛伊德判环能解数字会循环出现的题,比如说判断一个链表是不是循环链表。在程序中具体表现为 one = change(one); //一倍速度 two = change(change(two));//两倍速度 即一倍速度的人调用生成函数change一次,...

anzhuzeng4278的博客 185

Leetcode202-Happy Number

Leetcode202-Happy Number(Easy) 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 t

coderhuhy的专栏 963
上一篇: leetcode-203 Remove Linked List Elements
下一篇: leetcode-205 Isomorphic Strings
evolone
博客等级 码龄14年 399粉丝 98原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值