精華區beta Marginalman 關於我們 聯絡資訊
※ 引述《dont (dont)》之銘言: : ※ 引述《JerryChungYC (JerryChung)》之銘言: : : https://leetcode.com/problems/2-keys-keyboard : : 650. 2 Keys Keyboard 思路: 靠杯為什麼一堆人會想到要DP解 好可怕== 這題不就質因數分解加起來 :( 只剩我在寫這種國小作法了 class Solution { public: int minSteps(int n) { //find factor of n if(n == 1) return 0; vector<int> factor; for(int i = 2; i*i <= n; i++){ while(n % i == 0){ factor.push_back(i); n /= i; } } if(n != 1) factor.push_back(n); return accumulate(factor.begin(), factor.end(), 0); } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.52.197.90 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1724093485.A.C39.html
sixB: 不用開vector 找到直接加就好 我太笨了 08/20 02:51
dont: 大師 08/20 22:13