id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) { \n vector <long> ans;\n ans={1,2,3,4,5};\n if(n<=5) return (int)ans[n-1];\n queue<long>a1;\n queue<long>a3;\n queue<long>a5;\n a1.push(4);a1.push(6);a1.push(8);a1.push(10);\n a3.push(6);a3.push(9);a3.push(12);a3.push(15)... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\n using Int = std::int64_t;\npublic:\n int nthUglyNumber(int const n) {\n std::priority_queue<Int> ugly_numbers;\n std::queue<std::pair<Int, char>> q;\n q.emplace(1, '2');\n while (!q.empty()) {\n auto const [u, tag] = q.front(); q.pop();\n ugly_numbers.push(u);\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n int a = 2, b = 3, c = 5;\n int l1 = 1, l2 = 1, l3 = 1;\n int tr = 1;\n set<int> si;\n si.insert(tr);\n while (n-- > 1) {\n tr = min(min(l1 * a, l2 * b), l3 * c);\n si.insert(tr);\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "\nconst vector<int> limited_prime_factors{ 2,3,5, };\nclass Solution {\npublic:\n\n\n int nthUglyNumber(int n) {\n set<long long> befores{ 1,};\n long long current_value = 1;\n for (int i = 1; i < n; i++) {\n long long current_min = INT_MAX;\n for (auto it = be... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n int a = 2, b = 3, c = 5;\n int l1 = 1, l2 = 1, l3 = 1;\n int tr = 1;\n set<int> si;\n si.insert(tr);\n while (n-- > 1) {\n tr = min(min(l1 * a, l2 * b), l3 * c);\n si.insert(tr);\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n std::set<int> nums{1};\n\n for (int i = 0; i < n - 1; ++ i) {\n const int a = 2 * *nums.upper_bound(*--nums.end() / 2);\n const int b = 3 * *nums.upper_bound(*--nums.end() / 3);\n const int c = 5 * *n... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n set<int> s;\n s.insert(1);\n vector<int> primes = {2, 3, 5};\n int k = 1, maxi = INT32_MAX;\n for(auto it = s.begin(); it != s.end(); it++){\n int i = *it;\n if(k == n) return i;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n vector<int> m_ugly;\n Solution()\n {\n m_ugly = getUgly();\n }\n\n\n int nthUglyNumber(int n)\n {\n ios_base::sync_with_stdio(false);\n return m_ugly[n - 1]; \n }\n\n vector<int> getUgly()\n {\n vector<int> ugly;\n\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n int a[2000];\n a[0] = 1;\n int q = 0, w = 0, e = 0;\n unordered_map<int ,int> ma;\n ma[1] = 1;\n for (int i=1; i<n; i++) {\n if (a[q]*2 <= a[w]*3 && a[q]*2 <= a[e]*5) {\n a[i] = a... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n vector<int> m_ugly;\n Solution()\n {\n m_ugly = getUgly();\n }\n\n\n int nthUglyNumber(int n)\n {\n ios_base::sync_with_stdio(false);\n return m_ugly[n - 1]; \n }\n\n vector<int> getUgly()\n {\n vector<int> ugly;\n\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n vector<int> m_ugly;\n Solution()\n {\n m_ugly = getUgly();\n }\n\n\n int nthUglyNumber(int n)\n {\n ios_base::sync_with_stdio(false);\n return m_ugly[n - 1]; \n }\n\n vector<int> getUgly()\n {\n vector<int> ugly;\n\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n set<int> st;\n st.insert(1);\n // 1\n // 1 2\n // 1 2 4 3\n // 1 2 3 4 5 6 8 \n // 1 2 3 4 5 6 8 9 10 12 15 16 \n // 1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32\n // 1 2 3 4 5 6 8... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n template <class T> using minHeap = priority_queue<T, vector<T>, greater<T>>;\n int nthUglyNumber(int n) {\n minHeap<int> pq;\n unordered_set<int> count;\n long long cur_max = 0;\n long long tmp_max = 0;\n\n pq.push(1);\n\n for (int... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long, vector<long>, greater<long>>pq;\n pq.push(1);\n unordered_set<long>st;\n st.insert(1);\n vector<int>primes= {2,3,5};\n long ans;\n while(n--){\n long long node= pq.to... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n std::unordered_map<unsigned, bool> exists;\n std::vector<unsigned> dp(n);\n dp[0] = 1;\n\n int index_2 = 0;\n int index_3 = 0;\n int index_5 = 0;\n\n auto update_index = [&exists, &dp](int& index, i... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n)\n {\n unordered_set<long> s;\n priority_queue<long, vector<long>, greater<long>> q;\n q.push(1);\n s.insert(1);\n\n for (int i = 1; i < n; ++i)\n {\n long curr = q.top();\n q.pop();\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long long, vector<long long>, greater<long long>> pq;\n pq.push(1);\n unordered_set<long long> nums;\n nums.insert(1);\n for (int i = 0; i < n; i++) {\n if (i + 1 == n)\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n if (n == 1) {\n return 1;\n }\n\n int result;\n\n priority_queue<int, vector<int>, greater<int>> minHeap;\n minHeap.push(2);\n minHeap.push(3);\n minHeap.push(5);\n\n unordered_set... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) \n {\n std::priority_queue<int, std::vector<int>, std::greater<int>> factors;\n factors.push(1);\n int count = 0;\n std::unordered_set<int> poppedFactors;\n while(true)\n {\n if(poppedFactors.fin... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n long nthUglyNumber(int n) {\n vector<long> vecs(1, 1);\n vector<int> primes = {2, 3, 5};\n vector<int> indices = {0, 0, 0};\n for (int i = 0; i < n; ++i) {\n vector<long> ugly_cands = {\n vecs[indices[0]] * primes[0], \n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n //i know the first ugly number so let dp[n] denote the nth ugly number\n vector<long long>dp(n+1,0);\n unordered_set<long long>s;\n s.insert(1);\n dp[1]=1;\n for(int i=2;i<=n;i++){\n long long a... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n){\n vector<int64_t> bag(n,0);\n int p=1;\n int two=0,three=0,five=0;\n bag[0] = 1;\n set<int> used;\n for(;p<n;p++){\n int64_t ans = min({2*bag[two],3*bag[three],5*bag[five]});\n if(used.f... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n // int count = 1;\n // priority_queue<int, vector<int>, greater<int>> pq;\n // unordered_set<int> nums_set;\n // pq.push(1);\n // int result = 1;\n // while (nums_set.size() < n) {\n // result =... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n int one = 0, two = 0, three = 0;\n unordered_map<int, int> used;\n used[0] = 1;\n\n vector<int> ans;\n ans.push_back(1);\n for (int i = 2; i <= n; i++) {\n int v1 = 1;\n int v2 = 1;\n... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n std::vector<int> ugly = {1};\n std::unordered_set<int> ugly_set = {1};\n std::vector<int> primes = {2, 3, 5};\n std::vector<int> new_ugly;\n std::vector<int> pointers = {0, 0, 0};\n while (ugly.size() != n... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n int one = 0, two = 0, three = 0;\n unordered_map<int, int> used;\n used[0] = 1;\n\n vector<int> ans;\n ans.push_back(1);\n for (int i = 2; i <= n; i++) {\n int v1 = 1;\n int v2 = 1;\n... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n \n vector<int> vals(1, 1);\n set<int> singleset;\n singleset.insert(1);\n \n int last2 = 0;\n int last3 = 0;\n int last5 = 0;\n \n while(true){\n \n int a ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int>primes = {2,3,5};\n priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>>pq;\n pq.push({1,0});\n while(n>1)\n {\n n--;\n int uglynum = pq.top()[0];\n int... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "// O(n logn) time using hb-BST\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> primes = {2, 3, 5};\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> seenNumbers;\n seenNumbers.push({1, 0});\n while(n > 1) {\n int num = s... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long, vector<long>, greater<long>> pq;\n pq.push(1);\n int i = 0;\n long target = 0;\n vector<int> factors{2, 3, 5};\n unordered_set<long> visited;\n while (i<n){\n target ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n\n \n\n priority_queue<long,vector<long>,greater<long>>pq;\n unordered_set<long>st ;\n int cnt=0;\n int i=1;\n pq.push(1);\n\n while(!pq.empty()){\n long val=pq.top();\n pq.pop(... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n if (n <= 6)\n return n;\n\n std::unordered_set<int64_t> numbers;\n std::priority_queue<int64_t, std::vector<int64_t>, std::greater<int64_t>>\n candidates;\n candidates.push(1);\n const std::vector<int64_t> mult({2, 3, 5});... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "#define ll long long int\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n if(n==1)\n return 1;\n\n int rem = n-2;\n \n priority_queue<ll, vector<ll>, greater<ll>> pq;\n \n pq.push(2);\n pq.push(3);\n pq.push(5);\n \n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> p = {2, 3, 5};\n priority_queue<int, vector<int>, greater<int>>pq;\n pq.push(1);\n unordered_set<int> seen;\n int curr;\n for(int i = 0;i < n;i++) {\n curr = pq.top();\n p... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\nint nthUglyNumber(int n) \n{\n priority_queue<int> pq;\n unordered_set<int> s;\n pq.push(-1);\n int num;\n for(int i = 1;i<=n;i++)\n {\n num = pq.top();\n //cout<<num<<endl;\n pq.pop();\n if(num>INT_MIN/2 && s.find(num*2) == s.end()) ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n\n vector<int> prime = {2, 3, 5};\n priority_queue<int, vector<int>, greater<int>> uglyHeap;\n unordered_set<int> visited;\n\n uglyHeap.push(1);\n visited.insert(1);\n\n int currUgly;\n for (int i = ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "#include <queue>\n#include <vector>\n#include <iostream>\n#include <unordered_set>\n#include <climits>\n\nclass Solution {\npublic:\n\n // 2 3 5 -> generate\n // remove smallest in heap -> multiply by either 2 3 5\n struct Compare {\n // const is promise to not modify the object\n bo... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n bool isUgly(int n) {\n if(n==0) return false;\n \n while(n%2==0 || n%3==0 || n%5==0 ){\n if(n%2==0) \n n/=2;\n else if(n%3==0)\n n/=3;\n else if(n%5==0)\n n/=5;\n\n \n }\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> dp(n,1);\n set<long long> s;\n for(int i=1;i<n;i++){\n s.insert((long long)dp[i-1]*2);\n s.insert((long long)dp[i-1]*3);\n s.insert((long long)dp[i-1]*5);\n dp[i] = *s.be... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n map<long long,int> mp;\n mp[1]++;\n for(auto it:mp){\n n--;\n long long num=it.first;\n if(n==0) return num;\n mp[num*2]++;\n mp[num*3]++;\n mp[num*5]++;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n map<long long,int> m;\n m[1] = 1;\n auto itr = m.begin();\n n--;\n for(;itr!=m.end() && n;itr++)\n {\n n--;\n m[itr->first*2] = 1;\n m[itr->first*3] = 1;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "// naive apply ugly number 1 for each number\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long long, vector<long long>, greater<long long>> pq;\n unordered_set<long long> set;\n pq.push(1);\n int count = 0;\n long long ans = 1;\n whil... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n unordered_set<long long> seen; // Use long long to handle large numbers\n priority_queue<long long, vector<long long>, greater<long long>> pq;\n \n seen.insert(1);\n pq.push(1);\n \n int count = 0;... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<long> multipliers;\n multipliers.push_back(2);\n multipliers.push_back(3);\n multipliers.push_back(5);\n priority_queue<long, vector<long>, greater<long>> pq;\n unordered_set<long> distinct;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n int ans = 0;\n priority_queue<long long, vector<long long>, greater<long long>> q;\n unordered_set<long long> seen; // To avoid duplicates\n q.push(1);\n seen.in... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n // priority_queue<int,vector<int>,greater<int>>pq;\n // pq.push(1);\n set<long long>s;\n s.insert(1ll);\n vector<long long>vec(n+1);\n vec[1] = 1;\n int idx = 1;\n while(idx<=n){\n\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n std::vector<int64_t> ugly(n);\n std::set<int64_t> next;\n ugly[0] = 1;\n next.insert(ugly[0]*2);\n next.insert(ugly[0]*3);\n next.insert(ugly[0]*5);\n int cnt = 1;\n while( cnt < n ) {\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<long long> arr2;\n vector<long long> arr3;\n vector<long long> arr5;\n vector<long long> result;\n if(n==1){\n return 1; \n }\n else{\n result.push_back(1);\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "\nlong long my_pow(long long a, int n) {\n if (n == 0) return 1;\n if (n == 1 && a == 1) return a;\n if (n % 2 == 0) return my_pow(a * a, n / 2);\n return a * my_pow(a, n - 1);\n}\n\nclass Solution {\n\n struct number {\n int pow2;\n int pow3;\n int pow5;\n\n bool... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n set<int>st;\n st.insert(1);\n vector<int>ds={2,3,5};\n priority_queue<long long int,vector<long long int>,greater<long long int>>pq;\n pq.push(1);\n int cnt=1;\n while(cnt<n){\n long long... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n std::priority_queue<long long, std::vector<long long>, std::greater<long long>> pq;\n pq.push(1);\n\n set<long int> search;\n search.insert(1);\n \n int arr[]={1,2,3,5};\n int pop_count=0;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n std::priority_queue<long long, std::vector<long long>, std::greater<long long>> pq{};\n pq.push(1LL);\n std::vector<long long> primes = {2LL, 3LL, 5LL};\n std::set<long long> visited{};\n int a{};\n for (i... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n if(n==0) return 1 ;\n\n set<long long int> seen ;\n\n priority_queue<long long int,vector<long long int>,greater<long long int>> min_heap ;\n\n min_heap.push(1) ;\n seen.insert(1) ;\n for(int i = 1 ; i < n... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "const static auto io_speed_up = []() {\n std::ios::sync_with_stdio(0);\n cin.tie(0);\n FILE *fptr = fopen(\"user.out\", \"w\");\n int x, out = 0, i;\n while (!cin.eof()) {\n if (cin.peek() == '[') cin.ignore();\n else break;\n out = 0;\n i = 0;\n while (cin... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "const static auto io_speed_up = []() {\n std::ios::sync_with_stdio(0);\n cin.tie(0);\n FILE *fptr = fopen(\"user.out\", \"w\");\n int x, out = 0, i;\n while (!cin.eof()) {\n if (cin.peek() == '[') cin.ignore();\n else break;\n out = 0;\n i = 0;\n while (cin... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n \n int n = nums.size();\n\n for(int i=0; i<n; i++){\n int index = (nums[i] % (n+2));\n\n if(index <n){\n nums[index] += (n+2); \n }\n }\n\n for(int i =0... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n \n int startSum = (nums.size()*(nums.size() + 1))/2;\n\n for(int i = 0; i < nums.size() ; i++)\n {\n startSum = startSum - nums[i];\n }\n\n return startSum;\n }\n};",
"memory": ... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int res = nums.size();\n \n for (int i = 0; i < nums.size(); i++) {\n res += i - nums[i];\n }\n \n return res; \n }\n};",
"memory": "20400"
} |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n=nums.size();\n int i;\n for( i=1;i<=n;i++){\n int f=0;\n for(int j=0;j<n;j++){\n if(nums[j]==i){\n f=1;\n break;\n }\n ... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\n public:\n int missingNumber(vector<int>& nums) {\n int ans = nums.size();\n\n for (int i = 0; i < nums.size(); ++i)\n ans ^= i ^ nums[i];\n\n return ans;\n }\n};",
"memory": "20500"
} |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n = nums.size();\n int Xor = 0;\n for(int i=0; i<=n; i++){\n Xor = Xor ^ i;\n }\n\n for(int num: nums){\n Xor = Xor ^ num;\n }\n\n return Xor;\n }\n};",
"m... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n=nums.size();\n int n1=n;\n int sum=0;\n int s=0;\n while(n1>0)\n {\n s=s+n1;\n n1--;\n }\n for(int i=0;i<n;i++)\n {\n sum=sum+(n-nums[i... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& arr) {\n int ans=0;\n for(int i=1;i<arr.size()+1;i++){\n ans^=i;\n }\n for(int i=0;i<arr.size();i++){\n ans^=arr[i];\n \n }\n return ans;\n }\n};",
"memory": "20600"... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n \n int m=nums.size();\n int flag;\nfor(int i=0;i<(m+1);i++)\n{flag=0;\nfor(int j=0;j<m;j++) \n {if(nums[j]==i)\n {flag=1;\n break;}}\n if(flag==0)\n {return i;}}\n return -1;\n }\n\n};",
"memory": "20700"
} |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 0 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int m=nums.size();\n int flag;\nfor(int i=0;i<(m+1);i++)\n{flag=0;\nfor(int j=0;j<m;j++) \n {if(nums[j]==i)\n {flag=1;\n break;}}\n if(flag==0)\n {return i;}}\n return -1;\n \n }\n};",
"memory": "20700"
} |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n=nums.size();\n int es=n*(n+1)/2;\n for(int i=0; i<n; i++)\n es-=nums[i];\n return es;\n }\n};",
"memory": "20800"
} |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n = nums.size();\n int expected_sum = n * (n + 1) / 2;\n int actual_sum = 0;\n \n for (int i = 0; i < n; i++) {\n actual_sum += nums[i];\n }\n \n return expected_su... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n=nums.size(); \n vector<int> ans(n+1,1);\n for(int i=0;i<n;i++){\n ans[nums[i]]=0;\n } \n for(int i=0;i<n+1;i++){\n if(ans[i]==1)return i;\n }\n return -1;\n }\n};",
"memory": "20900"
... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int size = nums.size();\n vector<bool>bools(size+1, false);\n for(int i = 0; i < size; i++){\n bools[nums[i]] = true;\n }\n if(bools[0] == true) {\n vector<bool>::iterator it = find(bools.begin()... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n=nums.size();\n vector<int> hash(n + 1, 0);\n for(int i=0;i<n;i++){\n hash[nums[i]]++;\n }\n for(int i=0;i<=n;i++){\n if(hash[i]==0){\n return i;\n ... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n = nums.size();\n int arr[n+1];\n memset(arr, 0, (n+1)*sizeof(int));\n for(int i = 0; i < nums.size(); i++)\n {\n arr[nums[i]]++;\n }\n\n for(int i = 0; i < n+1; i++)\n ... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int size = nums.size();\n vector<int> hashArray(size+1,-1);\n for(int i=0;i<size;i++){\n hashArray[nums[i]] = nums[i];\n }\n for(int i=0;i<hashArray.size();i++){\n if(hashArray[i]==-1) return i;\n }\n ... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n = nums.size();\n vector<int>v(n+1,-1);\n for(int i =0;i<nums.size();i++){\n v[nums[i]] = nums[i];\n }\n for(int i =0;i<v.size();i++){\n if(v[i]==-1)return i;\n }\n ... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n = nums.size();\n vector<int>hash(n+1,0);\n\n for(int i=0; i<n; i++){\n hash[nums[i]]++;\n }\n for(int i=0; i<=n; i++){\n if ( hash[i]!=1){\n return i;\n }... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 2 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n // //using natural number sum\n // int n=nums.size();\n // int og_sum=n*(n+1)/2;\n // int sum=0;\n // //finding sum of elements in the vector\n // for(int i=0;i<nums.size();i++){\n // ... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 3 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = 0;\n while(n<nums.size()){\n if(n != nums[n]){\n break;\n }\n n++;\n }\n return n;\n }\n};\n",
"memory": ... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 3 | {
"code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n = nums.size();\n \n \n vector<int> hash(n + 1, 0);\n\n \n for (int i = 0; i < n; i++) {\n hash[nums[i]] = 1;\n }\n\n for (i... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 3 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n\n if(nums[0] != 0) return 0;\n if(nums[n-1] != n) return n;\n\n for(int i = 1; i < n; i++){\n if(nums[i] != i){\n ret... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 3 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int i;\n for(i = 0; i < nums.size(); i++){\n if(nums[i] != i){\n return i;\n }\n }\n return i;\n }\n};",
"memory": "21400"
} |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 3 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int s=nums.size();\n \n int n=0;\n\n \n sort(nums.begin(),nums.end());\n \n\n for(int j=0;j<s;j++){\n if(nums[j]!=j){\n return j;\n }\n }\n ... |
268 | <p>Given an array <code>nums</code> containing <code>n</code> distinct numbers in the range <code>[0, n]</code>, return <em>the only number in the range that is missing from the array.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [3,0,1]
<strong>Output... | 3 | {
"code": "class Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n int c = nums.size();\n sort(nums.begin(), nums.end());\n int i;\n for (i = 0; i < c; i++) {\n if (nums[i] != i) {\n return i;\n }\n }\n return i;\n }\n};... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 0 | {
"code": "class Solution {\npublic:\n unordered_map<int, unordered_map<int, bool>> dp;\n bool can(vector<int>& stones, int unit, int i) {\n if(i >= stones.size() - 1) return true;\n if(dp.count(i) && dp[i].count(unit)) {\n return dp[i][unit];\n }\n \n for(int step ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 0 | {
"code": "class Solution {\npublic:\n unordered_map<int, unordered_map<int, bool>> memo;\n\n bool canCrossHelper(vector<int>& stones, int index, int jump) {\n if (index == stones.size() - 1)\n return true;\n if (memo.count(index) && memo[index].count(jump))\n return memo[ind... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 0 | {
"code": "class Solution {\npublic:\nset<int>st;\nmap<pair<int,int>,bool>dp;\n bool fn(int i, int last, int jump){\n if(dp.find({i,jump})!=dp.end())\n return dp[{i,jump}];\n if(st.find(i)==st.end()||i<0||i>last)\n return dp[{i,jump}]=0;\n if(i==last)\n return dp[{i,jump}]=1;\n int a=0, b=0, c=0;... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 0 | {
"code": "class Solution {\npublic:\n bool helper(vector<int>& stones , int i , int k, unordered_map<string,bool>& dp){\n if(i == stones.size()-1){\n return true;\n }\n \n string key = to_string(i) + \",\" + to_string(k);\n if(dp.find(key) != dp.end()){\n r... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 1 | {
"code": "class Solution {\npublic:\n bool ans;\n bool jump(int u, int j, vector<vector<bool>> &dp, vector<vector<bool>> &vis, vector<int>&v){\n int n=v.size();\n if(u==n-1){\n vis[u][j]=true;\n dp[u][j]=true;\n ans=true;\n return true;\n }\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 1 | {
"code": "struct pair_hash {\n inline std::size_t operator()(const std::pair<int,int> & v) const {\n return v.first*31+v.second;\n }\n};\nclass Solution {\npublic:\n\tbool canCross(vector<int>& stones) {\n\t\tunordered_set<int> s;\n\t\tmemo = new unordered_set<pair<int, int>, pair_hash>;\n\t\tfor(int a ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 1 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n if (stones[1] != 1) {\n return false;\n }\n std::vector<std::unordered_map<int, bool>> dp(n + 1);\n dp[0][0] = true;\n for (int i = 1; i < n; ++i) {\n int k = i - 1;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 1 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n if (stones[1] != 1) return false;\n vector<unordered_set<int>> dp(n, unordered_set<int>());\n dp[1].insert(1);\n for (int i = 2; i < n; i++) {\n for (int j = 1; j < i... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 1 | {
"code": "#include <vector>\n#include <unordered_map>\n#include <unordered_set>\n\nclass Solution {\npublic:\n bool canCross(std::vector<int>& stones) {\n if (stones[1] != 1) {\n return false;\n }\n\n std::unordered_map<int, int> memo;\n for (int i = 0; i < stones.size(); ++... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 1 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n if(stones[1]-stones[0] != 1) return false;\n unordered_map<int, int> stone_map;\n for(int i=0;i<stones.size();i++) {\n stone_map[stones[i]] = i;\n }\n unordered_map<int, unordered_set<int> > ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n\n if (stones[1] != 1)\n return false;\n\n unordered_map<int, unordered_set<int>> dp;\n\n for (int stone : stones) {\n dp[stone] = unordered_set<int>();\n }\n dp[stones[0]].insert(1... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n if (stones[1] != 1) return false; // If the first jump is not 1, frog can't make the first jump\n\n // Hash map to store the possible jumps at each stone\n unordered_map<int, unordered_set<int>> stoneJumps;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n if (n >= 2)\n {\n if (stones[1] != 1)\n {\n return false;\n }\n\n if (n == 2)\n {\n return true; ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool rec(set<int>& stone_hai, int i, int last_step, unordered_map<int, unordered_map<int, int>>& memo, int target) {\n // Pruning\n if (i > target || i < 0 || last_step <= 0) return false;\n if (stone_hai.find(i) == stone_hai.end()) return false;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\n vector<int>a;\n int n;\n int dp[2010][5010];\n unordered_map<int,int>mp;\n\n int rec(int x,int j){\n if(x==n-1){\n return 1;\n \n }\n \n //if(x==n)return 1;\n\n if(dp[x][j]!=-1)return dp[x][j];\n\n int ans=0;\n ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n\n //int dp[2001][2001];\n unordered_map<int,unordered_map<int,int>>dp;\n\n int solve(unordered_map<int,int>&stones,int i,int k,int n){\n //cout<<i<<\" \";\n if(i>n || i<0 || k<0) return 0;\n\n if(i==n) return 1;\n\n int a=0;\n\n if(dp[... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& a) {\n long n = a.size();\n \n unordered_map<long,long>idx;\n\n\n for(int i=0;i<n;i++)\n {\n idx[a[i]] = i+1;\n }\n\n long dp[2000][2000];\n memset(dp,0,sizeof(dp));\n long N ... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "#include <vector>\n#include <unordered_map>\n#include <unordered_set>\nusing namespace std;\n\nclass Solution {\npublic:\n bool canCross(vector<int>& stones) {\n int n = stones.size();\n unordered_map<int, unordered_set<int>> mp;\n \n // Initialize the map with stone position... |
403 | <p>A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.</p>
<p>Given a list of <code>stones</code> positions (in units) in sorted <strong>ascending order</strong>, determ... | 2 | {
"code": "class Solution {\npublic:\n bool canCross(vector<int>& stones) {\n const int n = stones.size();\n vector<vector<char>> dp(n, vector<char>(n+5, -1));\n function<bool(int,int)> solve = [&](int i, int j) {\n if (j == 0) return false;\n if (i == n-1) return true;\n char& ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.