剑指Offer-- 丑数

class Solution {
public:
    int GetUglyNumber_Solution(int index) {
        int res = 0, i = 1,tmp;
        int arr[index];
        int ptrto2 = 0, ptrto3 = 0, ptrto5 = 0;
        arr[0] = 1;
        
        while (i <= index - 1){
            tmp = minOf3(arr[ptrto2]*2, arr[ptrto3]*3, arr[ptrto5]*5);
            if (tmp == arr[ptrto2]*2){
                arr[i] = tmp;
                ptrto2 ++;
            }
            if (tmp == arr[ptrto3]*3){
                arr[i] = tmp;
                ptrto3 ++;
            }
            if (tmp == arr[ptrto5]*5){
                arr[i] = tmp;
                ptrto5 ++;
            }
            i++;
        }
        return arr[index - 1];
    }
    int minOf3(int a, int b, int c){
        int minzhi = 0;
        minzhi = a < b ? a : b ;
        minzhi = minzhi < c ? minzhi : c;
        return minzhi;
    }
};

 

posted @ 2017-07-09 22:17  爱简单的Paul  阅读(143)  评论(0编辑  收藏  举报