C++ || Easy Solution || Solved in O(n) || have a look✔
Intuition\n\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Tim
# Intuition\n![leetcode2.PNG](https://assets.leetcode.com/users/images/9e230ffe-3b7d-4b08-8875-2e90a95119e7_1723957075.489404.png)\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int nthUglyNumber(int n) {\n        vector<int>arr(n+1);\n        arr[1]=1;\n\n        int a=1;\n        int b=1;\n        int c=1;\n        for(int i=2;i<=n;i++){\n            int i1= arr[a]*2;\n            int i2= arr[b]*3;\n            int i3= arr[c]*5;\n            int num = min({i1,i2,i3});\n            arr[i]=num;\n            if(num==i1)  a++;\n            if(num==i2)  b++;\n            if(num==i3)  c++;\n        }\n        return arr[n];\n    }\n\n\n\n    //TLE\n    // bool isugly(int num){\n    //     if(num==1) return true;\n    //     while(num!=1){\n    //         if(num%2==0){\n    //             num = num/2;\n    //         }\n    //         else if(num%3==0){\n    //             num = num/3;\n    //         }\n    //         else if(num%5==0){\n    //             num = num/5;\n    //         }\n    //         else return false;\n    //     }\n    //     return true; \n    // }\n    // int nthUglyNumber(int n) {\n    //     int num=1;\n    //     int ans;\n    //     for(int i=1;i<=n;){\n    //         if(isugly(num)==true){\n    //             ans =num;\n    //             i++;\n    //         }\n    //         num++;\n    //     }\n    //     return ans;\n    // }\n};\n```
['C++']