Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間1年前 (2024/11/04 08:16), 編輯推噓1(101)
留言2則, 2人參與, 1年前最新討論串1071/1548 (看更多)
3163. 超簡單 不知道為啥5個月前的我會MLE 完全照著題目要求跑就好 一個字一個字讀 class Solution { public: string compressedString(string word) { if(word.length() == 0) return ""; string res = ""; char c = word[0]; int cnt = 0; int len = word.length(); for(int i = 0; i < len ; i++){ if(word[i] != c){ if(cnt > 0){ res += ('0' + cnt); res += c; } c = word[i]; cnt = 1; } else{ cnt++; } if(cnt == 9){ res += '9'; res += c; cnt = 0; } } if(cnt > 0){ res += ('0' + cnt); res += word[len-1]; } return res; } }; ----- Sent from JPTT on my iPad -- 很姆的咪 姆之咪 http://i.imgur.com/5sw7QOj.jpg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1730679412.A.92F.html

11/04 08:17, 1年前 , 1F
大師
11/04 08:17, 1F

11/04 08:42, 1年前 , 2F
大師
11/04 08:42, 2F
文章代碼(AID): #1dA19qal (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dA19qal (Marginalman)