当前位置:网站首页>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;}};边栏推荐
猜你喜欢

1161 最大层内元素和——Leetcode天天刷【BFS】(2022.7.31)

高效目标检测:动态候选较大程度提升检测精度(附论文下载)

(十六)51单片机——红外遥控

微导纳米IPO过会:年营收4.28亿 君联与高瓴是股东
[email protected] 610/[email protected] 594/Alexa 56"/>染料修饰核酸RNA|[email protected] 610/[email protected] 594/Alexa 56

力扣203-移除链表元素——链表

RNA-ATTO 390|RNA-ATTO 425|RNA-ATTO 465|RNA-ATTO 488|RNA-ATTO 495|RNA-ATTO 520近红外荧光染料标记核糖核酸RNA

单调栈及其应用

为什么 BI 软件都搞不定关联分析

Anaconda virtual environment migration
随机推荐
子树的大小
小马智行起诉擎天智卡:索赔6000万 彭军称要斗争到底
刷题错题录1-隐式转换与精度丢失
盲埋孔PCB叠孔设计的利与弊
转运RNA(tRNA)甲基化修饰7-甲基胞嘧啶(m7C)|tRNA-m7G
【STM32】标准库-自定义BootLoader
List类的超详细解析!(超2w+字)
高并发,你真的理解透彻了吗?
ESP8266-Arduino编程实例-MCP4725数模转换器驱动
力扣59-螺旋矩阵 II——边界判断
charles配置客户端请求全部不走缓存
数学之美 第六章——信息的度量和作用
EasyCVR平台海康摄像头语音对讲功能配置的3个注意事项
揭秘5名运维如何轻松管理数亿级流量系统
安装anaconda并创建虚拟环境
MySQL Basics
【leetcode】剑指 Offer II 008. 和大于等于 target 的最短子数组(滑动窗口,双指针)
leetcode 899. 有序队列
node版本切换工具NVM以及npm源管理器nrm
wordpress建立数据库连接时出错