[LeetCode 258] Add Digits

野火STM32F407(骄阳)+无刷直流驱动板+永磁同步电机控制学习记录(四)(基于HAL库) 以上内容都是参考别人资料自学的,很多地方都是凭感觉,因为理论部分不太会算,只要电机能转就行,其他性能指标都没考虑,因为不会,所以这纯属是学习记录帖。带宽在500时,电流波动小,但是响应很慢,就是堵转后不太容易恢复转动。速度环带宽设定小了,响应不够快,带宽设定大了波动比较大,电机感觉起来也震一点,而且,当带宽设到200的时候,启动直接就锁死了,应该是PI增益设定太大了。电流环带宽的试验:去掉速度环,让Iq_Set=2,Ud=0,此时电机是电流环闭环控制,用手堵转电机然后松开,看电流的波动以及响应情况。 阅读详情

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 = 111 + 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;
    }



在摩尔线程 MTT S80 上使用 Ollama 进行 DeepSeek R1 蒸馏版模型推理 本文主要介绍了如何在摩尔线程 MTT S80 上通过 Ollama 快速完成DeepSeek R1 蒸馏系列模型的推理。 阅读详情

相关推荐

【2021工业图像异常检测文献】DRÆM: 基于判别性训练的重建嵌入表面异常检测方法

DRÆM – A discriminatively trained reconstruction embedding for surface anomaly detection

qq_1532145264的博客 1457

Add Digits -- 增加数字

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

whyalwaysmea 674

小红书直播弹幕采集

本文主要介绍小红书直播间弹幕的采集,便于进行直播数据监控与直播数据进行分析。

tdl320721的博客 2455

LeetCodeAdd Digits(各位相加)

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

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

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的博客 384

各位相加-leetcode解题

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

dearcandy的博客 495

Add Digits 各位相加

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

qq_26410101的博客 247

[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的博客 3461

leetcode.258.Add Digits

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

RaymondWong的博客 252

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的博客 523

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

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

prayyojay的博客 388

[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的博客 131

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的笔记 661

LeetCode - 258. Add Digits

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

168

Leetcode 258. Add Digits

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

weixin_30418341的博客 61

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

西施豆腐渣 7462

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 1124

LeetCode 258. Add Digits

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

weixin_30298497的博客 112

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

知足常乐,知行合一 365

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 842

leetcode258. Add Digits

problem 258. Add Digits solution1: class Solution { public: int addDigits(int num) { int sum = 0; int n = num; while(n/10) { sum = n/10 + n...

weixin_30481087的博客 88

最新2025江西省村界村级行政区划矢量shp数据下载

最新2025江西省村界村级行政区划矢量shp数据,几万个面,属性包含村、社区乡、街道镇、市多级属性,非常准确

三相逆变器PLECS仿真

基于PLECS的三相你不去PLECS仿真,采用PLES的C脚本编写程序,可以实现SVPWM调制

上一篇: [LeetCode 208] Implement Trie (Prefix Tree)
下一篇: [LeetCode 236] Lowest Common Ancestor of a Binary Tree
Mavs
博客等级 码龄16年 166粉丝 296原创
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值