id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n std::sort(nums.begin(), nums.end());\n\n // remove duplicates\n auto new_end = std::unique(nums.begin(), nums.end());\n int dup_count = nums.end() - new_end;\n nums.erase(new_end, nums.end());\n\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n std::sort(nums.begin(), nums.end(), [](int a, int b) {return a>b;});\n std::vector<int> h;\n // std::unordered_set<int> c;\n int max_continues = 0;\n int last_number=0;\n for (int i : nums) {\n... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "static const int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n int minOperations(std::vector<int>& nums) {\n std::sort(nums.begin(), nums.end());\n std::vector<int> dup = {0};\n dup.reserve(nums.size());\n for (int i = 1; i < n... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "static const int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n int minOperations(std::vector<int>& nums) {\n std::sort(nums.begin(), nums.end());\n std::vector<int> dup = {0};\n dup.reserve(nums.size());\n for (int i = 1; i < n... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n vector<int> v = nums;\n sort(v.begin(), v.end());\n //remove duplicates from the sorted array\n v.erase(unique(v.begin(), v.end()), v.end());\n int m = v.size(), max_len ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n sort(begin(nums), end(nums));\n int n = nums.size();\n vector<int> dup(n);\n int mx = 1;\n for(int i=0; i<n; ++i) {\n if(i>0)\n {\n dup[i] = dup[i-1];\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "#define A(x) (x).begin(), (x).end()\n#define sz(x) ((int)(x).size())\n\nclass Solution {\n int solve(vector<int> &v, int LEN) {\n int n = v.size();\n queue<int> q;\n int best = LEN;\n for(int i = n - 1; i >= 0; --i) {\n int start = v[i];\n int end = v[i]... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n=nums.size();\n vector<int> temp;\n temp.push_back(nums[0]);\n for(int i=1;i<n;i++)\n {if(nums[i]!=nums[i-1])\n temp.push_back(nums[i]);\n co... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n vector<int> uni;\n uni.push_back(nums[0]);\n for(int i = 1; i<n; i++){\n if(nums[i] != uni[uni.size() - 1]){\n uni.pu... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n vector<int> unique(vector<int> &a){\n int n = a.size();\n vector<int> ans;\n for(int i = 1 ; i < n ; i++){\n if(a[i] != a[i - 1]) ans.push_back(a[i - 1]); \n }\n ans.push_back(a[n - 1]);\n return ans;\n }\n int minOpe... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<int> temp;\n for(int i=0;i<nums.size();){\n int j=i;\n while(j<nums.size() && nums[i]==nums[j]){\n j++;\n }\n temp.... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n vector<int>s;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size();i++){\n if(s.empty()||s[s.size()-1]!=nums[i]){\n s.push_back(nums[i]);\n }\n }\n int ans... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "\nvoid print(auto v)\n{\n // cout << (#v) << \": \";\n for (auto ele : v)\n cout << ele << \" \";\n cout << endl;\n}\n\nclass Solution {\npublic:\n int minOperations(vector<int>& v) {\n int n = v.size();\n sort(v.begin(), v.end());\n vector<int> dist_cnt(n);\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n= nums.size();\n sort(nums.begin(),nums.end());\n vector<int> a;\n a.push_back(nums[0]);\n \n for(int i=1; i<n; i++){\n if(nums[i-1]!=nums[i]){\n a.push_back(nums... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n vector<long long>v;\n sort(nums.begin(),nums.end());\n v.push_back(nums[0]);\n for(int i=1;i<n;++i){\n int pos=v.size()-1;\n if(nums[i]!=v[pos]) v.push_back(... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n unordered_map<int,int> values;\n\n int start= 0, end = 0, result = nums.size() - 1;\n while (end < nums.size()) {\n values[nums[end]] += 1;\n\n while ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n // [4,5,8,8,9,9]\n sort(nums.begin(), nums.end());\n unordered_map<int,int> m;\n int n = nums.size();\n int res = n; \n int l = 0;\n for(int i = 0; i < n; i++){\n while(nums[i... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n std::sort(nums.begin(), nums.end(), [](int a, int b) {return a>b;});\n std::vector<int> h;\n std::unordered_set<int> c;\n int max_continues = 0;\n for (int i : nums) {\n while(h.size() > 0 ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n std::sort(nums.begin(), nums.end(), [](int a, int b) {return a>b;});\n std::vector<int> h;\n std::unordered_set<int> c;\n int max_continues = 0;\n for (int i : nums) {\n while(h.size() > 0 ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n std::sort(nums.begin(), nums.end(), [](int a, int b) {return a>b;});\n std::vector<int> h;\n std::unordered_set<int> c;\n int max_continues = 0;\n for (int i : nums) {\n while(h.size() > 0 ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int i=0;\n int ans = 0,curr = 0;\n int n = nums.size();\n unordered_map<int,int> m;\n for(int j=0;j<n;j++){\n // cout<<nums[j]<<\" \";\n m... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n unordered_set<int> a(nums.begin(), nums.end());\n int res = n, r=0;\n nums.erase(unique(begin(nums), end(nums)), end(nums));\n int m = n... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n unordered_map<int ,int>mp;\n\n int n = nums.size();\n for(int i = 0; i<n ;i++){\n\n if(mp[nums[i]] == 1){\n nums[i] = INT_MAX;\n }\n else {\n mp[nums[i... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n int i = 0, j = 0; \n int result = 0;\n int repeated = 0;\n unordered_map<int, int> mp;\n while (i < n) {\n while (j < ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n // int binary_search(vector<int>&nums, int idx, int val){\n // return x - idx;\n // }\n int minOperations(vector<int>& nums) {\n int n = nums.size(), res = INT_MAX;\n set<int> s(nums.begin(), nums.end());\n nums.clear();\n nums.assign(... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n set<int>st(nums.begin(),nums.end());\n nums.assign(st.begin(),st.end());\n int ans=INT_MAX;\n for(int i=0;i<nums.size();i++){\n int x=nums[i];\n int y=x+n-1;... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n set<int> st;\n for(auto it:nums)st.insert(it);\n nums.resize(0);\n for(auto it:st)nums.push_back(it);\n int ans=n;\n for(int i=0;i<nums.size();i++){\n in... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n set<int>st(nums.begin(),nums.end());\n nums.assign(st.begin(),st.end());\n int maxUnique = 0,left = 0;\n for (int right = 0; right < nums.size(); right++) {\n while (nums[right] - nums[left] >... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n set<int>st(nums.begin(),nums.end());\n nums.assign(st.begin(),st.end());\n int ans=INT_MAX;\n for(int i=0;i<nums.size();i++){\n int x=nums[i],y=x+n-1;\n int ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) \n {\n unordered_set<int> unique_nums(nums.begin(), nums.end());\n vector<int> sorted_nums(unique_nums.begin(), unique_nums.end());\n\n // Step 2: Sort the array to find the largest continuous subset\n sort(sorted_nums.b... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n unordered_set<int>S(nums.begin(),nums.end());\n vector<int>temp(S.begin(),S.end());\n int minOpe = INT_MAX;\n sort(temp.begin(),temp.end());\n for(int i=0;i<temp.size();i... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int count = 0;\n int n = nums.size();\n unordered_set<int> mp(nums.begin(), nums.end());\n vector<int> arr(mp.begin(), mp.end());\n sort(arr.begin(), arr.end());\n\n int window_size = 0;\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n unordered_map<int,int>mp;\n vector<int>pref(n+1,0);\n sort(nums.begin(),nums.end());\n for(int i=0;i<n;i++){\n int it=nums[i];\n mp[it]++;\n if(mp... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n unordered_map<int,int>mp;\n vector<int>pref(n+1,0);\n sort(nums.begin(),nums.end());\n for(int i=0;i<n;i++){\n int it=nums[i];\n mp[it]++;\n if(mp... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 1 | {
"code": "class Solution\n{\npublic:\n int minOperations(vector<int> &nums)\n {\n int n = nums.size();\n int i = 0, j = 0;\n set<int> hm;\n sort(nums.begin(), nums.end());\n\n int count = n;\n int c = 0;\n int curr = nums[i];\n int presentCount = 0;\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n\n sort(nums.begin(), nums.end());\n int n = nums.size();\n\n set<int> st(nums.begin(), nums.end());\n nums.assign(st.begin(), st.end());\n\n int r = 0;\n int ans = nums.back();\n for(int... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n // 1 2 4 5 7\n int n = nums.size();\n sort(nums.begin(),nums.end());\n if(n==1)return 0;\n int ans = INT_MAX;\n int low = 0;\n int high = 0;\n int sz = 0;\n map<int,int> mp... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n\n int s=0,e=0, ans=n;\n int start = nums[0];\n set<int> st;\n\n while(e < n) {\n if(start+n-1 >= nums[e]) {\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n //max subarray such that diff(max-min)<=n and all numbers are unique\n int n =nums.size();\n int end =0,begin=0,maxi = 0;\n sort(nums.begin(),nums.end());\n unordered_map<int,int> mp;\n //monot... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int n = nums.size(), minOp= n-1;\n\n int count = 0; // for distinct num\n unordered_map<int, int> map;\n map[-1] = 0;\n for (int i = 0; i < n; i++) {\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n// TC O(NlogN), SC O(N)\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n int res = n;\n \n set<int> unique(nums.begin(), nums.end());\n vector<int> newNums(unique.begin(), unique.end());\n\n for(int i = 0; i < newNums.... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n set<int> s(nums.begin(), nums.end());\n vector<int> newNums;\n newNums.reserve(s.size());\n std::copy(s.begin(), s.end(), std::back_inserter(newNums));\n\n int n = nums.size();\n size_t ops = n... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n // Use a set to store only unique elements and sort them automatically\n set<int> s(nums.begin(), nums.end());\n vector<int> v(s.begin(), s.end());\n int m = v.size(), max_len =... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n set<int> s(nums.begin(), nums.end());\n vector<int> newNums;\n newNums.reserve(s.size());\n std::copy(s.begin(), s.end(), std::back_inserter(newNums));\n\n int n = nums.size();\n size_t ops = n... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n set<int>st(nums.begin(),nums.end());\n vector<int>temp(st.begin(),st.end());\n int ans=INT_MAX;\n for(int i=0;i<temp.size();i++){\n int higherBound=temp[i]+(n-1);\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\n public:\n int minOperations(vector<int> &nums) {\n std::ranges::sort(nums);\n int res = nums.size(), sz = nums.size();\n\n // Count the cumulative duplicates\n set<int> s;\n vector<int> dups(sz, 0);\n for (int i = 0; i < sz; ++i) {\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n std::ranges::sort(nums);\n int res = nums.size(), sz = nums.size();\n set<int> s;\n vector<int> dups(sz, 0);\n for (int i = 0; i < sz; ++i) {\n auto [it, inserted] = s.insert(nums[i]);\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n\n set<int> st(nums.begin(),nums.end());\n int ans = nums.size();\n sort(nums.begin(),nums.end());\n vector<int> temp(st.begin(),st.end());\n for(int i = 0;i<nums.size();i++){\n int left = n... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int findIndex(vector<int>& nums, int lim, int index) {\n int res = nums.size();\n int l = index, r = nums.size() - 1;\n while(l <= r) {\n int mid = l + (r - l) / 2;\n if(nums[mid] > lim) {\n res = mid;\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n set<int> st(nums.begin(), nums.end());\n vector<int> v(st.begin(), st.end());\n\n sort(nums.begin(), nums.end());\n\n // for (int i: v)\n // cout<<i<<\" \";\n // cout<<endl;\n \n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n set<int> st(nums.begin(), nums.end());\n vector<int> v(st.begin(), st.end());\n\n sort(nums.begin(), nums.end());\n\n for (int i: v)\n cout<<i<<\" \";\n cout<<endl;\n \n int a... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n set<int> st(nums.begin(), nums.end());\n vector<int> v(st.begin(), st.end());\n\n sort(nums.begin(), nums.end());\n\n // for (int i: v)\n // cout<<i<<\" \";\n // cout<<endl;\n \n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n unordered_set<int> unqEles;\n\n vector<int> unqs;\n for(auto num : nums){\n if(unqEles.find(num) == unqEles.end()){\n unqs.push_back(num);\n unqEles.insert(num);\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 2 | {
"code": "class Solution {\npublic:\n int findIndex(vector<int>& nums, int lim, int index) {\n int res = nums.size();\n int l = index, r = nums.size() - 1;\n while(l <= r) {\n int mid = l + (r - l) / 2;\n if(nums[mid] > lim) {\n res = mid;\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int ans = INT_MAX; \n int n = nums.size();\n sort(nums.begin() , nums.end());\n set<int> st(nums.begin() , nums.end());\n vector<int> num(st.begin() , st.end());\n\n for(int i = 0; i<num.size()... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "/* Watch Editorial */\n\nclass Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n int ans = n;\n \n // std::set automatically sorts\n set<int> unique(nums.begin(), nums.end());\n vector<int> newNums;\n for (int num : uni... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n set <int> s(nums.begin(), nums.end());\n vector <int> arr;\n for(int num : s)arr.push_back(num);\n //iterate and ending at current, how many we need, and how many we have (with ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n\n set<int>st(nums.begin(), nums.end());\n\n vector<int>v;\n\n for(auto it : st)\n {\n v.push_back(it);\n }\n\n int ans=nums.size()-1;\n\n for(int i=0;i<v.size();i++)\n ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n set<int> s(nums.begin(), nums.end());\n int ans = INT_MAX;\n vector<int> temp;\n for (auto x : s)\n temp.push_back(x);\n int n = nums.size();\n for (int i = 0; i < temp.size(); i++) ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n int n = nums.size();\n int ans = n;\n\n set<int> unique(begin(nums), end(nums));\n vector<int> newNums;\n for (int num: unique){\n newNums.push_back(num);\n }\n\n in... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n\n int minOperations(vector<int>& nums) \n {\n int n = nums.size();\n int i;\n set<int> s;\n for(i=0;i<n;i++)\n {\n s.insert(nums[i]);\n }\n vector<int> v;\n for(auto itr : s)\n {\n v.push_b... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n= nums.size();\n int ans=n;\n set<int> st(nums.begin(),nums.end());\n vector<int> nw;\n for(int num:st)\n nw.push_back(num);\n for(int i=0;i<nw.size();i++){\n int lt=... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n map<int,int> freq;\n for(int &x : nums){\n freq[x]++;\n }\n\n vector<pair<int,int>> arr(freq.begin(),freq.end());\n\n int m = arr.size();\n int ans = 1e... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n // fm-vo\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n map<int, int> mp;\n vector<int> arr;\n for(auto i: nums) {\n if(mp.find(i) == mp.end()) {\n arr.push_back(i);\n }\n mp[i] ... |
2,119 | <p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>
<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>
<ul>
<li>All elements i... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n= nums.size();\n \n set<int>st;\n for(int i=0; i<n; i++){\n st.insert(nums[i]);\n }\n vector<int>v;\n for(auto it:st){\n v.push_back(it);\n }\n s... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "class Solution {\npublic:\n bool func(TreeNode* root1, TreeNode* root2){\n if(!root1 && !root2) return true;\n if((!root1 && root2) || (root1 && !root2)) return false;\n if(root1->val!=root2->val) return false;\n bool n1 = func(root1->left, root2->right);\n bool n2 = f... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
101 | <p>Given the <code>root</code> of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg" style="width: 354px; height: 291px;" /... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> levelOrder(TreeNode* root) {\n vector<vector<int>> order;\n if (!root) return order;\n\n queue<TreeNode*> q;\n q.push(root);\n int size;\n while (!q.empty()) {\n size = q.size();\n\n vector<i... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> levelOrder(TreeNode* root) {\n vector<vector<int>> order;\n if (!root) return order;\n\n queue<TreeNode*> q;\n q.push(root);\n int size;\n while (!q.empty()) {\n size = q.size();\n\n vector<i... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> levelOrder(TreeNode* root) {\n vector<vector<int>> order;\n if (!root) return order;\n\n queue<TreeNode*> q;\n q.push(root);\n int size;\n while (!q.empty()) {\n size = q.size();\n\n vector<i... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> levelOrder(TreeNode* root) {\n vector<vector<int>> order;\n if (!root) return order;\n\n queue<TreeNode*> q;\n q.push(root);\n int size;\n while (!q.empty()) {\n size = q.size();\n\n vector<i... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> levelOrder(TreeNode* root) {\n vector<vector<int>> order;\n if (!root) return order;\n\n queue<TreeNode*> q;\n q.push(root);\n int size;\n while (!q.empty()) {\n size = q.size();\n\n vector<i... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> levelOrder(TreeNode* root) {\n vector<vector<int>>ans;\n if(root==NULL)return ans;\n queue<TreeNode*>q;\n q.push(root);\n while(!q.empty()) {\n int s = q.size();\n vector<int>v;\n for(int ... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "class Solution {\npublic:\n // void traverse(TreeNode* root, int n, vector<vector<int>>& ans){\n // if(root == NULL) return;\n // if (n >= ans.size()) {\n // ans.push_back(vector<int>());\n // }\n // ans[n].push_back(root -> val);\n // traverse(root -> left, n+1... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
102 | <p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes' values</em>. (i.e., from left to right, level by level).</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.