当前位置:网站首页>leetcode 1837. The sum of the digits in the K-base representation
leetcode 1837. The sum of the digits in the K-base representation
2022-08-03 20:10:00 【Luna who can program】
Given an integer n (base 10) and a base k , please convert n from base 10 to base k, calculate and return the sum of the converted digits.
After conversion, the individual digits should be treated as decimal digits, and their sum should also be returned in decimal notation.
Example 1:
Input: n = 34, k = 6
Output: 9
Explanation: 34 (decimal) is represented as 54 in hexadecimal.5 + 4 = 9 .
Example 2:
Input: n = 10, k = 10
Output: 1
Explanation: n itself is base 10.1 + 0 = 1 .
Tip:
1 <= n <= 100
2 <= k <= 10
class Solution {public:int sumBase(int n, int k){int he=0;while(n){he+=(n%k);n/=k;}return he;}};边栏推荐
猜你喜欢

EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成

RNA核糖核酸修饰荧光染料|HiLyte Fluor 488/555/594/647/680/750标记RNA核糖核酸

不要再用if-else

从文本匹配到语义相关——新闻相似度计算的一般思路

安装anaconda并创建虚拟环境

Anaconda virtual environment migration

Statistical machine learning 】 【 linear regression model

危化企业双重预防机制数字化建设进入全面实施阶段

化算力为战力:宁夏中卫的数字化转型启示录

622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
随机推荐
pytorch框架实现老照片修复功能详细演示(GPU版)
【飞控开发高级教程3】疯壳·开源编队无人机-定高、定点、悬停
微导纳米IPO过会:年营收4.28亿 君联与高瓴是股东
Alexa染料标记RNA核糖核酸|RNA-Alexa 514|RNA-Alexa 488|RNA-Alexa 430
染料修饰核酸RNA|[email protected] 610/[email protected] 594/Alexa 56
MapReduce介绍及执行过程
EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成
leetcode 剑指 Offer 15. 二进制中1的个数
不知道这4种缓存模式,敢说懂缓存吗?
【leetcode】剑指 Offer II 008. 和大于等于 target 的最短子数组(滑动窗口,双指针)
【leetcode】剑指 Offer II 009. 乘积小于 K 的子数组(滑动窗口、双指针)
「学习笔记」高斯消元
高并发,你真的理解透彻了吗?
调用EasyCVR接口时视频流请求出现404,并报错SSL Error,是什么原因?
从腾讯阿里等大厂出来创业搞 Web3、元宇宙的人在搞什么
【STM32】标准库-自定义BootLoader
The sword refers to Offer II 044. The maximum value of each level of the binary tree-dfs method
2022.8.2
Detailed demonstration pytorch framework implementations old photo repair (GPU)
ESP8266-Arduino编程实例-BH1750FVI环境光传感器驱动