258. Add Digits [easy] (Python)

【十万字拆解】从零开始实现GPT-2(完整版) 本文是一篇 14 万字、从零硬核实现 GPT 的保姆级指南。内容全面覆盖四个阶段:①从最基础的 Bigram 语言模型切入,跑通数据处理与训练闭环;②仿照 Transformer 架构,深度研究 Multi-Head Attention、残差网络、LayerNorm 及 Dropout 的底层数学与代码实现;③从零构建BPE 分词器,对齐 GPT-2 规范;④从头搭建 GPT-1/2 工业级预训练流程,包含混合精度、梯度累积等十余项硬件级工程调优,并在 AutoDL 算力平台上从0开始训练!适合所有层次! 阅读详情

题目链接

https://leetcode.com/problems/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 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?

题目翻译

给定一个非负整数,将该整数的所有数字的和作为新的整数,重复直至得到只有一个数的整数。
比如:给定num=38,上述过程为:3 + 8 = 11, 1 + 1 = 2。因为2只有一个数字,所以返回2。
进一步:你能不用迭代或循环,在O(1)时间解决该问题吗?

思路方法

Hint:
1. A naive implementation of the above process is trivial. Could you come up with other methods?
2. What are all the possible results?
3. How do they occur, periodically or randomly?
4. You may find this Wikipedia article useful.

思路一

先不考虑“进一步”,根据定义来循环计算,效率低,但是可以AC。

代码

class Solution(object):
    def addDigits(self, num):
        """
        :type num: int
        :rtype: int
        """
        while num > 9:
            s = 0
            while num >= 1:
                s += num%10
                num /= 10
            num = s
        return num

思路二

根据提示,当输入从1到100变化时,可以发现,输出在“1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,…”这样循环。于是,就有了下面O(1)的算法。
dr(n) = 0, if n = 0
dr(n) = 9, if n != 0 and n mod 9 == 0
dr(n) = n mod 9, if n mod 9 != 0
或,
dr(n) = 1 + (n-1) mod 9

这个问题又叫做“digit root”问题,参看:
https://en.wikipedia.org/wiki/Digital_root#Congruence_formula

代码一

class Solution(object):
    def addDigits(self, num):
        """
        :type num: int
        :rtype: int
        """
        if num == 0:
            return 0
        else:
            return 1 + (num - 1) % 9

代码二

class Solution(object):
    def addDigits(self, num):
        """
        :type num: int
        :rtype: int
        """
        if num == 0:
            return 0
        elif num % 9 == 0:
            return 9
        else:
            return num % 9

PS: 新手刷LeetCode,新手写博客,写错了或者写的不清楚还请帮忙指出,谢谢!
转载请注明:http://blog.csdn.net/coder_orz/article/details/51378231

PnP 单目相机位姿估计(二):solvePnP利用二维码求解相机世界坐标 前言 原理简介 输入参数准备 1 objectPoints特征点世界坐标 2 imagePoints特征点在摄像头下的像素点坐标 3cameraMatrixdistCoeffs内参矩阵和畸变矩阵 相机世界坐标的求解 1求世界坐标中的点在相机坐标系下的坐标 2求相机在世界坐标中的坐标 3效果求解相机在世界坐标系下的坐标点 4求解代码1.前言  很多时候,当我们利用单目相机获取图像时,往往只能获取图像中 阅读详情

相关推荐

用逐飞STC32G库做个智能小车:编码器测速、PWM调电机、ADC读电池电压(完整项目)

本文详细介绍了如何使用逐飞科技的STC32G12K128开源库构建智能小车项目,涵盖编码器测速、PWM电机控制和电池电压监测等核心功能。通过硬件选型、开发环境搭建、代码实现及调试技巧的全流程讲解,帮助开发者快速掌握基于STC32G的嵌入式系统开发,实现高性能的智能小车控制。

weixin_42526417的博客 200

Add Digits -- 增加数字

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

whyalwaysmea 675

STM32 SYSTICK定时器及延时函数详解

STM32 SYSTICK及延时函数详解 SysTick定时器 SysTick定时器被捆绑在NVIC中,用于产生SYSTICK异常(异常号:15)。在以前,大多操作系统需要一个硬件定时器来产生操作系统需要的滴答中断,作为整个系统的时基。例如,为多个任务许以不同数目的时间片,确保没有一个任务能霸占系统;或者把每个定时器周期的某个时间范围赐予特定的任务等,还有操作系统提供的各种定时功能,都与这个滴答定时器有关。因此,需要一个定时器来产生周期性的中断,而且最好还让用户程序不能随意访问它的寄存器,以维持操作系统“心

w1050321758的博客 2374

【LeetCode】Add Digits(各位相加)

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

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

无人机遥控Lora信号时域、频域与时频图分析指南

面对一段未知的射频信号,如何判断它是否是Lora调制?时域波形、频域谱线与时频图是信号分析的三个互补维度。Lora采用chirp扩频调制,恒包络特性使其在时域上看似噪声,频域上能量均匀分布,唯有时频图能清晰呈现符号结构与调制参数。通过短时傅里叶变换(STFT),可直观提取信号带宽、符号周期与扩展因子,从而为无人机遥控信号的解调解码提供可靠依据。本文结合实际采集样本,系统讲解三域分析的核心方法、参数反推技巧与常见陷阱,帮助工程师快速建立对Lora信号的直观认知,提升信号逆向分析与工程实践效率。

weixin_29164091的博客 278

基于C#的ASP.NET开发的党史学习网站课设

开展党史学习教育,就是要以史为镜、以史明志,把苦难辉煌的过去、日新月异的现在、光明宏大的未来贯通起来,在鉴往知来中砥砺前行,在乱云飞渡中把准航向,在凝心聚力中团结奋斗,共同创造新的历史伟业。登陆按钮与数据库进行连接,逻辑实现是如图3.1.3所示,自己定义一个SQL查询语句,将账号、密码放入SQL查询语句中,用sqlDataReader.HasRows语句进行逐一比较,找出结果,将用户名存入session并调用cookies,如果结果存在就关闭数据库,进行数据跳转,并弹出登陆成功的提示框,并关闭数据库。

m0_62408555的博客 979

Python : 深度学习DIGITS

DIGITS并不是一个真正的深度学习库(虽然它是用Python写的)。DIGITS(深度学习GPU培训系统)实际上是用于培训Caffe深度学习模式的web应用程序(虽然我认为你可以破解源代码然后使用Caffe以外其他的后端进行工作,但这听起来就像一场噩梦)。 如果你曾经用过Caffe,那么你就会知道通过它的终端来定义.prototxt文件、生成图像数据、运行网络并监管你的网络训练是相当繁琐的。 D...

weixin_44523387的博客 3326

【时时三省】vector cast 常见错误解决/vcast常见错误解决

介绍在使用 vector cast/vcast 软件的过程中,遇到的异常问题。其它异常可以私信解决(购买专栏的前提下)。

时时三省的博客 460

DIGITS使用步骤

1 切换到你的digits目录下 2 ./digits-devserver 启动digits 3 在浏览器上输入 http://0.0.0.0.5000/ (将其作为一个服务器) 4 制作数据库,制作模型     自己在用vgg模型时遇到的问题   需要自定义网络(将train_val.prototxt进行修改)再下载一个预训练模型。 下面是网上搜到的修改prototxt的方法

fish20122016的博客 1万+

Python爬取公交线路信息及站点shp数据 文末附数据下载地址

三、现在已经获取到了各个线路名称、链接,以及所途径的上下行站点,那么接下来就应该对开始对第三页url进行信息采集,即本次爬虫的最终目的:爬取所有站点的GPS坐标数据。但坑就坑在,二环一号线属于环线,所以只有左侧有站点数据,而其他非环线车次的站点数据分有上下行,如果用正则匹配,则分不清楚到底哪些是上行站点哪些是下行站点。以前爬过百度地图,当时用的是API平台,加上网站比较规范,所以标签节点什么的都比较清晰,但这次由于特殊原因所选择的网站为公交网,废话不多说直接开始吧。checi=二环一号线。

J_Giser的博客 1325

华为MetaERP月结加速方案:并行关账技术深度解析

【摘要】华为MetaERP并行关账技术通过创新架构设计,将传统串行月结流程(8-12小时)优化为并行执行(2-4小时)。关键技术包括:1)基于DAG引擎的任务依赖分析,实现模块/子任务三级并行;2)Saga模式分布式事务保障数据一致性;3)动态资源分配算法提升CPU利用率至60-80%。实施效果显示月结时间缩短70%,成功率提升至99.8%,错误恢复时间减少75%。该方案为大型企业ERP系统提供了高效的月结加速方案,未来还将结合AI调度与混合云扩展持续优化。

金牌架构师 1443

digit函数

digit函数 时间限制: 1000 ms         内存限制: 65536 KB 提交数: 420     通过数: 247  【题目描述】 在程序中定义一函数digit(n,k),它能分离出整数n从右边数第k个数字。 【输入】 正整数n和k。 【输出】 一个数字。 【输入样例】 31859 3 【输出样例】 8 【来源

小马的博客 1万+

PCL 改进的RANSAC算法实现点云粗配准【2024最新版】

一种改进的RANSAC点云粗配准算法,具体改进见论文:“Pose Estimation using Local Structure-Specific Shape and Appearance Context”

点云侠的博客 37万+

Leetcode----258.Add Digits(easy)

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

Txiaomiao的博客 534

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

【LeetCode】 258. Add Digits 解题报告(Java & Python)

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

负雪明烛 1737

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

【Leetcode】258. Add Digits(配数学证明)

题目地址: https://leetcode.com/problems/add-digits/ 给定一个非负整数nnn,加总其各位数之和得到另一个整数,再重复做此操作直到得到一位数。求那个一位数。 首先如果这个数本身就是一位数,则返回自己;否则判断一下其能否被999整除,如果能则返回999,否则返回余数。代码如下: public class Solution { public int addDigits(int num) { if (num < 10) {

数学、算法爱好者的博客 252

温度PID控制PLC程序

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

初识“列表”--Python入门笔记

列表(List)是 Python 中最基本、最常用的可变序列(Mutable Sequence),可以动态增删改,支持多种数据类型混合存储,是 Python 编程的核心数据结构之一。

2301_79195831的博客 1636

各位相加-leetcode解题

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

dearcandy的博客 497

leetcode(3),Add Digits详解(python)

question: 一个非负整数,将所有位数上的数字相加,得到一个数,如果得数不是个位数,继续相加,直到得数为个位数为止。 例入,num=38,3+8=11,1+1=2。写一段代码,计算所有数相加的得数。 answer: 初级:使用循环或递归解题。 def adddigits(num): snum = str(num) count = len(snum) re

吴祺育的技术记录 1789

Add Digits 各位相加

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

qq_26410101的博客 250

python中digits用法_在sklearn digits examp中使用自己的图像

所以我一直在研究sklearn和python,试图理解机器学习是如何工作的。我的基本例子是对的,但有一件事我正在努力。在例如,假设我正在使用digits数据集,一旦我准备好并测试了分类器。在这个例子中,我该如何使用自己手写的图像呢?在我设法加载了图像并用matplotlib读取了它的像素,但是我从中得到了一个数组(8,8,3),而digits数据集的一个样本的形状是(8,8)。在这是我用来训练分类...

weixin_39954487的博客 2909

ArcGis如何插入图片_如何批量插入图片,并自动排版——《超级处理器》应用

下表中,如何将图片插入到对应的单元格中,数据不多的话,可以手动操作。如果有几十个数据,甚至更多的数据,怎么批量快速插入,并排版好呢?人员名单我们用《超级处理器》中的批量插入图片功能,可以自动完成,具体操作步骤如下:操作流程打开超级处理器;点击批量插入图片;插入方式,选择根据单元格内容添加图片;大小设定选择指定大小,高度输入30,宽度输入25;点击确定;选中要插入的图片并点击打开;选择图片名称所在单...

weixin_39520149的博客 3012

python学习之——Add Digits

Given a non-negative integernum, repeatedly add all its digits until the result has only one digit. For example: Givennum = 38, the process is like:3 + 8 = 11,1 + 1 = 2. Since2has only one dig...

weixin_30443731的博客 224

addDigits 加数字

问题: 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 on...

初学者乐园的博客 481

LeetCode之路:258. Add Digits

LeetCode之路:258. Add Digits 一、引言这是一道比较难的题,之所以下这个定义,是因为要做出来这道题的正确答案,需要一点点数学知识。当然,能看到这篇博客的人,大部分都是程序员,那么作为程序员,我们自然有自己的方法来实现它,这样看来,这道题其实也不算太难。直接上题目信息吧: Given a non-negative integer num, repeatedly add all its

(ÒωÓױ) 959

add digits java_【leetcode刷题】[简单]258. 各位相加(add digits)-java

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

weixin_29711757的博客 172
上一篇: 292. Nim Game [easy] (Python)
下一篇: 226. Invert Binary Tree [easy] (Python)
coder_orz
博客等级 码龄14年 102粉丝 90原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值