Re: [閒聊] 每日leetcode
就傻傻的照做
算是比較偏難的easy
比昨天的medium難一點
int getLucky(string s, int k) {
int ans = 0;
// Transform #1
for(auto c : s) {
int ord = c-'a'+1;
while(ord>0) {
ans += (ord%10);
ord /= 10;
}
}
// Transform #2~
for(int i=1; i<k; i++) {
int tmp = ans;
ans = 0;
while(tmp>0) {
ans += (tmp%10);
tmp /= 10;
}
}
return ans;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1725323965.A.95C.html
→
09/03 08:40,
1年前
, 1F
09/03 08:40, 1F
推
09/03 08:42,
1年前
, 2F
09/03 08:42, 2F
※ 編輯: DJYOMIYAHINA (125.229.37.69 臺灣), 09/03/2024 08:43:44
討論串 (同標題文章)
完整討論串 (本文為第 798 之 1548 篇):