[LeetCode 258] Add Digits

C++控制台实现简单的注册登录 C++控制台实现简单的注册登录 #include<iostream> #include<string> #include <vector> #include <conio.h> void Display();//调用display显示switch()界面 void Register();//注册 void Enter();//登录 using nam... 阅读详情

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

For example:

Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.

Follow up:

Could you do it without any loop/recursion in O(1) runtime?


Solution:

1. 逐位相加直到小于10

public int addDigits(int num) {
        while(num>=10){
            num = (num/10)+num%10;
        }
        return num;
    }

2.

通过输入距离来发现规律

123456789 10 11 12 13 14 15

123456789 1 2 3 4 5 6

public int addDigits(int num) {
        return 1 + (num-1)%9;
    }



【科研数据获取】根据Excel表个中的企业/公司信息批量获取经纬度坐标,并进行地图可视化 批量获取企业/公司的经纬度坐标,并进行地图可视化1 需求2 实现途径3 需求逐步实现 1 需求 在做项目的时候,老板或者项目答辩时候甲方最喜欢看到的就是可视化结果,尤其是涉及到地图可视化。很多时候会遇到企业/公司的数据,想要做地图可视化,必不可少的就是要获取它们具体地址:第一种就是像查户口一样精准一下具体的城镇街道,还有一种就是经纬度信息,前一种属于文字内容往往用于管理方面,第二种数字信息多用于数据处理与分析。 2 实现途径 获取地理信息数据,自然需要使用到地图的功能,这里直接采用百度地图的拾取坐标系统, 阅读详情

相关推荐

第七章 Wi-Fi连接过程

系列文章目录 第一章 国内下载AOSP最新源码的方法 第二章 下载AOSP WiFi相关的代码 第三章 将源码导入Android Studio(无需编译idegen) 文章目录系列文章目录前言一、Wi-Fi连接是什么?二、Wi-Fi连接的过程1. 手动连接总结 前言 Wi-Fi连接分为下面几种过程,每种的流程都有些许差异: 手动连接 自动连接 在BSS之间漫游 Passpoint热点连接 一、Wi-Fi连接是什么? Wi-Fi连接是指STA(手机)连接到AP(无线路由器)的过程,这个过程分为链路

Frank.Zhang的专栏 2527

【LeetCode】Add Digits(各位相加)

这道题是LeetCode里的第258道题。 题目描述: 给定一个非负整数num,反复将各个位上的数字相加,直到结果为一位数。 示例: 输入: 38 输出: 2 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2。由于2 是一位数,所以返回 2。 进阶: 你可以不使用循环或者递归,且在 O(1) 时间复杂度内解决这个问题吗? 如果我们用循环做的话,首先先...

『诞生之时已至,以此修正万象』 228

博途V17 & PLCSIM & FactoryIO 连接教程

PLCSIM V17 和 FactoryIO 连接教程前言一、软件版本二、连接步骤1. 连接PLCSIM2. 博途编程3.连接FactoryIO总结 前言 该文详细讲解了新手入门博途,并通过使用自带PLCSIM和FactoryIO实现连接。 一、软件版本 TIA Portal V17 S7-PLCSIM V17 Factory IO V2.5.1 二、连接步骤 1. 连接PLCSIM 打开PLCSIM 进入项目模式 新建仿真项目 2. 博途编程 将F

soledad_chao的博客 2万+

Add Digits -- 增加数字

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 给出一个正整数,对它的每一位进行相加,直到结果是个一位的数字。

whyalwaysmea 675

NOIP2008年普及组初赛题目答案及解析

NOIP2008年初赛详细题解

城南蝈蝈 926

[LaTeX] 调整参考文献的格式(References),包括作者名缩写,行距,字体,引用顺序等等

在此记录我对LaTeX中参考文献references的尝试,主要涵盖如题几个方面。

the Blog of 等不到天亮丶等时光 4万+

【LeetCode】第258题——各位相加(难度:简单)

【LeetCode】第258题——各位相加(难度:简单)题目描述解题思路代码详解注意点 题目描述 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。 示例: 输入: 38 输出: 2 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2。 由于 2 是一位数,所以返回 2。 进阶: 你可以不使用循环或者递归,且在 O(1) 时间复杂度内解决这个问题吗? 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/add-di

Se7en_Dayz的博客 390

ESP32-S3开发板实战:5分钟搞定智能门铃的音视频通话功能(附源码)

本文详细介绍了如何利用乐鑫ESP32-S3开发板快速实现智能门铃的实时音视频通话功能。通过ESP-ADF框架和RTC服务,开发者可在五分钟内完成环境搭建与核心功能调试,并附有源码和关键配置详解,为嵌入式音视频应用开发提供了高效实践路径。

web99的专栏 527

各位相加-leetcode解题

各位相加 Add Digits 题述 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。 示例: 输入: 38 输出: 2 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2。 由于 2 是一位数,所以返回 2。 进阶: 你可以不使用循环或者递归,且在 O(1) 时间复杂度内解决这个问题吗? 解题思路及代码 思路一 使用循环解题 :使用循环或递归来解决这个...

dearcandy的博客 496

高通ISP模块全解析:从Raw到JPEG的18个关键处理步骤(附避坑指南)

本文全面解析高通ISP模块从Raw到JPEG的18个关键处理步骤,涵盖原始数据预处理、色彩科学处理链、画质增强与降噪等核心环节。通过实战调优经验,揭示ISP架构中的技术原理与工程实践要点,帮助开发者避免常见问题,提升移动影像处理质量。

weixin_30399155的博客 359

【国产化信创实践】宝兰德bes中间件集成springboot

【国产化信创实践】宝兰德bes中间件集成springboot

项目管理、软件工厂、vue研发、Java研发、中国文化等。 1万+

Add Digits 各位相加

给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。 示例: 输入: 38 输出: 2 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2。 由于 2 是一位数,所以返回 2。 进阶: 你可以不使用循环或者递归,且在 O(1) 时间复杂度内解决这个问题吗? 思路:这道题的笨办法就不说了,说一个discuss里面很厉害的方法,可以实现O(1)的复杂度...

qq_26410101的博客 249

Vue2 - 详细实现网页 “开启录音并生成音频文件,上传到服务器效果“,浏览器录制外部音频调用麦克风并传到后端,兼容全部浏览器、支持 PC 网页或手机 H5 网页、可本地播放试听(详细示例运行代码)

vue,nuxt,uniapp,网页网站,麦克风,网页录音,MediaRecorder,浏览器录音,移动端h5网页,手机端录音,web网页录音,recorder-core官方文档,Recorder,非https怎么本地录音,录音报错失败,录音后怎么播放音频,如何获取录音mp3文件,解决一直不提示麦克风权限,小白详细教程,实时录音,调用浏览器麦克风录音,浏览器不兼容,wav,mp3,vue怎么实现网页录音呢,vue2网页录音并上传到服务器,web如何实现录制音频,vue网页录音,音频录制播放和上传服务器,vu

🏆 前端领域优质创作者 6003

[LeetCode]258. Add Digits

[LeetCode]258. Add Digits题目描述思路循环相加每一位 每次获取num的个位,加到和中,num = num / 10,循环直至num / 10为0,最后在外层sum += num, 对得到的sum进行判断,若大于等于10,递归处理 否则输出 详见代码代码class Solution { public: int addDigits(int num) {

Lcharon的博客 3465

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

leetcode.258.Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

RaymondWong的博客 255

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

leetcode 258. Add Digits

Add DigitsGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only on

Decorator2015的博客 528

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

LeetCode 258. Add Digits 题解(C++)

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

prayyojay的博客 391

[leetcode]258. Add Digits

[leetcode]258. Add Digits Analysis 厉害的人总是那么的厉害呀~—— [菜鸡反省中~] Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 简单题,直接看代码吧。 Implement cl...

weixin_32135877的博客 134

LeetCode - 258. Add Digits

链接 258. Add Digits 题意 给定一个非负整数,反复做如下操作:将它的各位数相加得到一个值,若该值位数仍大于1,重复以上操作,直到位数为1。 思路 模拟即可 代码 Java: public int addDigits(int num) { while(num>=10){ num = (num/10)+num%10; } ...

170

leetcode-258.add digits/Digital root

leetcode-258.Add DigitsGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since

绯浅yousa的笔记 666

Leetcode 258. Add Digits

转载于:https://www.cnblogs.com/winder-knight/p/9804070.html

weixin_30418341的博客 64

leetcode 258: Add Digits

Add Digits Total Accepted: 5383 Total Submissions: 11876 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 3

西施豆腐渣 7466

LeetCode 258: Add Digits 题解

刚开始以为是一道水题,一下就过了,结果题没看完,要求时间复杂度为O(1)O(1)。LeetCode 258: Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the pr

请叫我AXin 1132

LeetCode 258. Add Digits

258. Add Digits(各位相加) 题目:   给定一个非负整数num,反复将各个位上的数字相加,直到结果为一位数。   示例:   输入: 38   输出: 2   解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2。 由于2 是一位数,所以返回 2。   进阶:  你可以不使用循环或者递归,且在 O(1) 时间复杂度内解决这个问题吗...

weixin_30298497的博客 118

leetcode 258- Add Digits

leetcode题目汇集 — Add Digitsleetcode 258- Add Digits 题目要求 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process

知足常乐,知行合一 367

leetcode 258---Add Digits, 关于C++中负数取余

一切源于leetcode 258---Add Digits这道题,https://leetcode.com/problems/add-digits/ 题目的解法很简单,有两种公式,一种是我这种笨笨的人写的: class Solution { public: int addDigits(int num) { if(num==0) return 0;

ChenLI's blog 846
上一篇: [LeetCode 208] Implement Trie (Prefix Tree)
下一篇: [LeetCode 236] Lowest Common Ancestor of a Binary Tree
Mavs
博客等级 码龄17年 166粉丝 296原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值