当前位置:网站首页>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;}};
边栏推荐
猜你喜欢
随机推荐
codeforces:C. Maximum Subrectangle【前缀和 + 贪心 + 最小子数组和】
【HiFlow】经常忘记签到怎么办?使用腾讯云场景连接器每天提醒你。
Auto.js实现朋友圈自动点赞
EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成
【leetcode】剑指 Offer II 009. 乘积小于 K 的子数组(滑动窗口、双指针)
力扣707-设计链表——链表
tRNA修饰2-甲基胞嘧啶(m2C)|tRNA修饰m2G (N2-methylguanosine)
WPF .cs中使用资源文件中的ControlTemplate或Style并找到控件
ES6-箭头函数
收藏-即时通讯(IM)开源项目OpenIM-功能手册
leetcode 125. 验证回文串
华为设备配置VRRP负载分担
matplotlib画polygon, circle
从文本匹配到语义相关——新闻相似度计算的一般思路
花 30 美金请 AI 画家弄了个 logo,网友:画得非常好,下次别画了!
一种能有效缓解环境噪声对音频质量干扰的方案
剑指 Offer II 044. 二叉树每层的最大值-dfs法
async 和 await 原来这么简单
Anaconda virtual environment migration
数学之美 第六章——信息的度量和作用