C++ Easy solution with explanation
Approach\n1) Create a vector of size n called "numbers" to store the ugly numbers. Initialize the first element, numbers[0], as 1 since 1 is considered the firs
# Approach\n1) Create a vector of size n called "numbers" to store the ugly numbers. Initialize the first element, numbers[0], as 1 since 1 is considered the first ugly number.\n2) Initialize three variables: power2, power3, and power5. These variables will be used to track the indices of the numbers array that are multiplied by 2, 3, and 5 respectively.\n3) Start a loop from i=1 (second element) to i<n (nth element) to generate the remaining ugly numbers:\n- Calculate the next ugly number by taking the minimum value among numbers[power2] * 2, numbers[power3] * 3, and numbers[power5] * 5. This ensures that we always select the smallest possible ugly number at each step.\n- If the next ugly number is equal to numbers[power2] * 2, increment power2 by 1. This means that the next ugly number will be obtained by multiplying the current numbers[power2] with 2 in the next iteration.\n- If the next ugly number is equal to numbers[power3] * 3, increment power3 by 1. This means that the next ugly number will be obtained by multiplying the current numbers[power3] with 3 in the next iteration.\n- If the next ugly number is equal to numbers[power5] * 5, increment power5 by 1. This means that the next ugly number will be obtained by multiplying the current numbers[power5] with 5 in the next iteration.\n4) After the loop, the nth ugly number will be stored in numbers[n-1], so return that value.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\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> numbers(n);\n        numbers[0]=1;\n        int power2=0;\n        int power3=0;\n        int power5=0;\n        for(int i=1;i<n;i++){\n            numbers[i]=min(numbers[power2]*2, min(numbers[power3]*3,numbers[power5]*5));\n            if(numbers[i]==numbers[power2]*2){\n                power2++;\n            }\n            if(numbers[i]==numbers[power3]*3){\n                power3++;\n            }\n            if(numbers[i]==numbers[power5]*5){\n                power5++;\n            }\n        }\n        return numbers[n-1];\n    }\n};\n```\n**Please upvote if it helped. Happy Coding!**
['C++']