剑指offer 丑数

class Solution {
public:
	int GetUglyNumber_Solution(int index) {
		int cur1 = 0;
		int cur2 = 0;
		int cur3 = 0;
		vector tem;
		int cur;
		tem.push_back(1);
		for (int i = 1; i <= index; i++) {
			cur = min(min(tem[cur1] * 2, tem[cur2] * 3), tem[cur3] * 5);
			tem.push_back(cur);
			if (cur == tem[cur1] * 2)
				cur1++;
			if (cur == tem[cur2] * 3)
				cur2++;
			if(cur==tem[cur3]*5)
				cur3++;
		}
		return tem[index - 1];
	}
};

你可能感兴趣的:(剑指offer)