作者DJYOMIYAHINA (通通打死)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Tue Sep 3 08:39:23 2024
就傻傻的照做
算是比較偏難的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
→ JIWP: 別倦了 09/03 08:40
推 sustainer123: 大師 09/03 08:42
※ 編輯: DJYOMIYAHINA (125.229.37.69 臺灣), 09/03/2024 08:43:44