精華區beta Marginalman 關於我們 聯絡資訊
我自己寫是每個數字都算一次二進位轉換 看解答發現可以用類似DP來解 :O 338. Counting Bits class Solution { public: vector<int> countBits(int n) { vector<int> ans(n+1, 0); for(int i=0; i<n+1; i++){ ans[i]=ans[i/2]+i%2; } return ans; } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.40.62 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1708053402.A.B1A.html
sustainer123: 大師 02/16 11:25
Che31128: 大師 02/16 11:31
JIWP: 大師 02/16 11:34