LeetCode:Happy Number

LiblibAI新手教程:从零开始训练你的第一个LoRA模型(保姆级指南) 本文提供LiblibAI平台上从零开始训练LoRA模型的保姆级教程,涵盖数据准备、参数优化到效果调优全流程。详细解析LoRA技术优势,包括云端计算资源、自动化预处理工具等,帮助新手快速掌握自定义模型训练技巧,实现高效AI绘画创作。 阅读详情

Happy Number——LeetCode
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


就是按照题目一边一边循环来求出是不是和为1,如果不是1的话,总会是那些个数来回出现,用一个set去装一下sum,来判断一下就可以

public class Solution {

    public boolean isHappy(int n) {
        Set<Integer> set=new HashSet<Integer>();
        int sum=n;
        while(sum!=1){
            n=sum;
            sum=0;
            while(n!=0){
                int tmp=n%10;
                sum+=tmp*tmp;
                n=n/10;
            }
            if(set.contains(sum)){
                return false;
            }
            set.add(sum);
        }


        return true;
    }
}

代码大部分人都是一样的,只不过我在百度的时候发现,有的博客不光代码一样,连说的话都一样。
一如既往的开头:这道题是Leetcode上面的题,很简单balabala···
真是不装会死

视频倍速 - 在线调倍速的加速器APP工具 一刀工具箱APP提供一键可将手机上的视频倍速播放,可以调整视频倍速的加速器,调节视频的速度也就是调节视频的播放速度!一键可将手机上的视频倍速播放,可以调整视频倍速的加速器,调节视频的速度也就是调节视频的播放速度!视频倍速-在线调倍速的加速器-一刀工具箱APP。... 阅读详情

相关推荐

基于Dify1.9知识库流水线模板的思考——图像和表格数据处理

本文探讨了Dify1.9知识库流水线中LLM节点对文档图像/表格增强处理的优化方案。针对当前仅在内容后追加说明的简单做法,提出了结构化标注的改进方法:通过唯一ID和注释块标记图像/表格及其描述,确保内容可精准对齐。文章详细阐述了该方案的解析处理流程、数据结构化表示方法,以及在RAG检索和文档还原中的具体应用。关键经验包括:必须结构化标注非文本内容、LLM增强的必要性、语义向量化处理等。该方案解决了原始方法在内容重排、相似元素区分和检索精度等方面的问题。

roseey的专栏 1438

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

Ambari 3.0.0 + BigTop 3.3.0 源码编译与集群部署指南(Kylin V10 / aarch64)

仅仅是针对“应用商店目录(Applications Catalog)”的一个外围附属子模块(它不是 YARN 监控大盘,不影响 YARN UI 网页的主体使用),我们可以采用。自带的 Node 二进制是 x86_64 版本,在 ARM64(aarch64)容器上无法执行(Exit value: 126)。:Ambari Server/Agent 使用 JDK 17,BigTop 大数据组件(Hadoop/HBase/Spark 等)使用 JDK 8。,源码中包含 x86 特定的原生二进制文件。

amumu1992的博客 490

Leetcode 快乐数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

yanerhao的专栏 3045

AI人工智能全模态大模型架构:推动智能交通发展的架构设计

本文旨在阐述全模态大模型在智能交通领域的架构设计原理和应用方法。我们将探讨如何利用多模态AI技术解决交通流量预测、事故预警、路线优化等关键问题。文章将从基础概念入手,逐步深入技术细节,最后探讨实际应用和未来发展方向。全模态大模型:能够处理和理解多种数据模态(如图像、文本、语音等)的大型AI模型智能交通系统(ITS):利用先进技术优化交通流量和安全性的综合系统多模态融合:将不同数据源的信息整合处理的技术核心概念回顾全模态大模型是能够处理多种数据类型的强大AI系统。

AGI×大数据,开启智能时代的认知跃迁;解码AGI,赋能数据驱动的智能革命。 835

别再只跑recon-all了!FreeSurfer实战:从T1图像到freeview可视化的完整避坑指南

本文详细解析FreeSurfer从T1图像处理到freeview可视化的全流程,包括环境配置、recon-all深度解析、高级可视化技巧及性能优化策略。特别针对常见错误提供解决方案,帮助用户高效完成MRI数据分析,避免常见陷阱。

weixin_33404102的博客 353

leetcode刷题:Happy Number

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 equa

a1204800782的专栏 575

逆向实战:手把手教你用Frida绕过Flutter App的SSL Pinning(附脚本修改指南)

本文详细介绍了如何利用Frida工具绕过Flutter应用的SSL Pinning保护机制,包括静态分析定位关键函数、定制Frida Hook脚本以及流量捕获的完整解决方案。通过实战案例和脚本修改指南,帮助安全研究人员有效应对Flutter应用的安全挑战,特别适用于安卓平台的逆向工程和抓包需求。

weixin_28723171的博客 404

LeetCode--Happy Number

Problem: 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 o

peachli 404

别再只会插卡了!用示波器实测SIM卡上电时序与通信波形(附故障排查)

本文深入解析了SIM卡通信的电气信号与时序规则,通过示波器实测波形揭示SIM卡上电时序与通信协议的关键细节。从VCC、CLK、RST、DATA四路信号的协同工作,到ATR(Answer to Reset)的解析,再到常见故障的波形诊断与排查方法,为硬件工程师提供了实用的调试指南。文章还分享了高级调试技巧与现代化工具链搭建建议,帮助提升物联网设备SIM卡通信的可靠性与效率。

weixin_42567279的博客 328

第10.6章 FAST-LIO源码解读(三): iekf模块大揭秘,从公式到代码一看就懂

FAST-LIO中的IEKF模块解析:本文深入剖析了FAST-LIO定位框架中迭代扩展卡尔曼滤波(IEKF)的实现原理。文章首先介绍IEKF作为"激光+IMU融合"计算器的核心作用,解释其通过IMU高频预测和激光点云校正实现厘米级定位的原理。随后详细拆解了代码实现中的关键设计:包括状态量定义(位置、姿态、速度等)、过程噪声建模、状态转移方程推导,以及SO3与欧拉角转换等核心算法。特别强调了IEKF通过迭代优化解决非线性问题的优势,使其在无人机等快速运动场景中保持稳定定位。

行知SLAM 232

LeetCode题解: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 i

追风筝的吃货,汪~ 1317

Exploring Automated Distractor Generation for Math Multiple-choice Questions via Large Language Mode

多项选择题(MCQ)在几乎所有级别的教育中都无处不在,因为它们易于管理、评分,并且是评估和实践中可靠的格式。MCQ最重要的方面之一是干扰因素,即旨在针对真实学生常见错误或误解的不正确选项。迄今为止,对于教师和学习内容设计师来说,制作高质量的干扰物的任务在很大程度上仍然是一个劳动和时间密集型的过程,其可扩展性有限。在这项工作中,我们研究了数学MCQ领域的自动干扰物生成任务,并探索了从上下文学习到微调的各种基于大型语言模型(LLM)的方法。

c_cpp_csharp的专栏 317

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

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

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

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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

哈哈的个人专栏 2360

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

leetcode笔记:Happy Number

题目要求对任意一个正整数,不断各个数位上数字的平方和,若经过若干次运算后结果收敛到1,则该数字为Happy Number。

liyuefeilong的专栏 2229

leetcode: 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 th

gotobar的专栏 1133

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

ruzhuxiaogu的专栏 455

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

531

Leetcode: 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 squar

YMHH的专栏 468

[leetcode]: 202. Happy Number

1.题目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 square

沐沐余风的专栏 592
上一篇: Leetcode:Product of Array Except Self
下一篇: Leetcode:Valid Sudoku
「已注销」
博客等级 码龄11年 4粉丝 16原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值