题解 | #丑数#
丑数
https://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b
#include <type_traits> #include <vector> class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param index int整型 * @return int整型 */ int min(int a, int b, int c){ return std::min(a,std::min(b,c)); } int GetUglyNumber_Solution(int index) { // write code here if (index<= 6) { return index; } int a = 0; int b = 0; int c = 0; vector<int> res(index); res[0] = 1; for (int i = 1; i < index; ++i) { res[i] = min(res[a] * 2, res[b] * 3, res[c] *5 ); if (res[i] == res[a] * 2) { a++; } if (res[i] == res[b] * 3) { b++; } if (res[i] == res[c] * 5) { c++; } } return res[index-1]; } };
看的解析 晚上回去看看
note_coding 文章被收录于专栏
记录自己的解题思路, 欢迎评价