id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
0
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int cnt = 0;\n int n = s.size();\n for(int i = 0 ; i < n ; i++) if(s[i] == '1') cnt++;\n if(cnt == 0) return s;\n s[n-1] = '1';\n cnt--;\n int i = 0;\n while(i < n-1) {\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
0
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int numOfOne = 0;\n int n = s.size();\n for(char i: s) {\n if(i == '1') numOfOne ++;\n }\n int i;\n for(int i = 0; i < numOfOne-1; i++) {\n s[i] = '1';\n }\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
0
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int ones=0;\n for(auto& ch: s){\n if(ch=='1') ones++;\n }\n s[s.size()-1]='1';\n ones--;\n int i=0;\n \n while(ones--&& i<s.size()-1){\n s[i++]='1';\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
0
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n // Online C++ compiler to run C++ program online\n int i = 0,j=s.length()-1;\n while(j>i){\n //cout<<\" \"<<s<<\" \"<<i<<\" \"<<j<<\" \"<<s[j]<<\" \"<<s[i]<<endl;\n if(s[j]!='1'){\n j--;\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
0
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int length = s.length();\n int count_ones = -1;\n\n for (char c : s) {\n if (c == '1') {\n count_ones++;\n }\n }\n\n string result(length, '0');\n for (i...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
1
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n // Online C++ compiler to run C++ program online\n string ans;\n int count = 0;\n for(int i=0;i<s.length();i++){\n if(s[i]=='1'){\n count ++;\n ans+='1';\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
1
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int count_1 = 0;\n string l = \"\";\n for(int i = 0; i < s.size(); i++){\n if(s[i] == '1'){\n count_1++;\n }\n }\n for(int i = 0; i < s.size() - 1; i++){\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
1
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int count_1 = 0;\n string l = \"\";\n for(int i = 0; i < s.size(); i++){\n if(s[i] == '1'){\n count_1++;\n }\n }\n for(int i = 0; i < s.size() - 1; i++){\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
2
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n sort(begin(s), end(s), [](char a, char b)\n {\n return a > b;\n });\n\n char c = s[0];\n s = s.substr(1);\n s += c;\n return s;\n }\n};", "memory": "9000" }
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
2
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n string t ,c;\n for(char x : s)\n {\n if(x == '1') t.push_back(x);\n else c.push_back(x);\n }\n if(!t.empty())\n {\n t.back() = '0';\n t += c;\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
2
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int ones = count(s.begin(), s.end(), '1');\n int zeros = s.length() - ones;\n return string(ones - 1, '1') + string(zeros, '0') + '1';\n }\n};", "memory": "9200" }
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
2
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int z=0,o=0;\n for(int i=0;i<s.size();i++)\n {\n if(s[i]=='1')\n {\n o++;\n }\n else\n {\n z++;\n }\n }\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
2
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int ones_count = count(s.begin(), s.end(), '1');\n int zeros_count = s.length() - ones_count;\n return string(ones_count - 1, '1') + string(zeros_count, '0') + \"1\";\n }\n};", "memory": "9300" }
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
2
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int ones_count = count(s.begin(), s.end(), '1');\n int zeros_count = s.length() - ones_count;\n return string(ones_count - 1, '1') + string(zeros_count, '0') + \"1\";\n }\n};", "memory": "9400" }
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
2
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int count = 0;\n for(const auto c: s){\n if(c == '1') count+=1;\n }\n return std::string(count-1, '1') + std::string(s.size() - count, '0') + '1';\n }\n};", "memory": "9400" }
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int n=s.size(), ones=count(s.begin(), s.end(), '1'), zeros=n-ones;\n string ans=string(ones-1, '1')+string(zeros, '0')+string(1,'1');\n return ans;\n }\n};", "memory": "9500" }
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n string answ=\"\";\n map<char,int>m;\n for(auto i:s){\n if(i=='1'){m[i]++;}\n }\n int ans=m['1'];\n for(int i=0;i<ans-1;i++){answ+='1';}\n for(int i=0;i<s.size()-ans;i++){an...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n unordered_map<char,int> map1;\n for(char c:s){\n map1[c]++;\n }\n string res=\"\";\n while(res.size() <s.size()-1){\n if(map1['1']>1){\n res+='1';\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n map<char,int> m;\n for(auto i:s){\n m[i]++;\n }\n string ans = \"\";\n while(m['1'] != 1){\n ans.push_back('1');\n m['1']--;\n }\n while(m['0'] != 0){...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n map<char,int> m;\n for(auto i:s){\n m[i]++;\n }\n string ans = \"\";\n while(m['1'] != 1){\n ans.push_back('1');\n m['1']--;\n }\n while(m['0'] != 0){...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n map<char,int> m;\n for(auto i:s){\n m[i]++;\n }\n string ans = \"\";\n while(m['1'] != 1){\n ans.push_back('1');\n m['1']--;\n }\n while(m['0'] != 0){...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n string res = \"\";\n map <char, int> m;\n for(char c: s) {\n m[c]++;\n }\n if(m['1'] > 1) {\n for(int i=0; i<s.size()-1; i++) {\n if(m['1'] > 1) {\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n sort(s.rbegin(),s.rend());\n int cnt=0;\n for(int i=0; i<s.size(); i++)\n if(s[i]=='1') cnt++;\n if(cnt>=2){\n int x=-1;\n for(int i=0; i<s.size(); i++)\n i...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n sort(s.rbegin(),s.rend());\n int cnt=0;\n for(int i=0; i<s.size(); i++)\n if(s[i]=='1') cnt++;\n if(cnt>=2){\n int x=-1;\n for(int i=0; i<s.size(); i++)\n i...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) \n {\n string result;\n\n map<char,int> count;\n\n for (char c : s) count[c]++;\n\n result += string(count['1']-1, '1');\n result += string(count['0'], '0');\n result.push_back('1');\n\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n sort(s.rbegin(),s.rend());\n int cnt=0;\n for(int i=0; i<s.size(); i++)\n if(s[i]=='1') cnt++;\n if(cnt>=2){\n int x=-1;\n for(int i=0; i<s.size(); i++)\n i...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n sort(rbegin(s) , rend(s));\n int oneCnt = accumulate(begin(s) , end(s) , 0 , [&](int curr , char b){\n return curr + b - '0';\n });\n s[oneCnt - 1] = '0';\n s.back() = '1';\n retu...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "\nclass Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int count1 = 0;\n int count0 = 0;\n for (char c : s) {\n if (c == '1') {\n count1++;\n } else {\n count0++;\n }\n }\n string result ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n \n int cnt=0;\n int n=s.size();\n for(int i=0; i<n;i++){\n if(s[i]=='1'){\n cnt++;\n }\n }\n int zer=n-cnt;\n string ans=\"\";\n for(int i=...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
3
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n vector<int> vec(s.size(),0);\n int count=0;\n for(char ch: s)\n {\n if(ch=='1')count++;\n }\n int size=vec.size();\n vec[size-1]=1;\n count--;\n int i=0;\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\nclass Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n const int n=grid.size(), m=grid[0].size();\n int Row[n], Col[m];\n memset(Row, 0, n*sizeof(int));\n memset(Col, 0, m*sizeof(int));\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n\n const uint_least32_t colHeight = grid.size();\n const uint_least32_t rowWidth = grid[0].size();\n\n array<uint_least32_t, (int)2e5> rowsCache;\n rowsCache.fill(0);\n\n for (...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n vector<int>onesr(n,0);\n vector<int>onesc(m,0);\n // vector<vector<int>>diff(n,vector<int>(m,0));\n for(int i=0;i<n;i++){\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n int n = grid.size(), m = grid[0].size();\n vector<pair<int, int>> countRow(n);\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n vector<vector<int>>ans(n,vector<int>(m,0));\n for(int i=0;i<n;i++)\n {\n int ct0=0,ct1=0;\n for(int j=0;j<m;...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> result(n, vector<int>(m, 0)); \n for(int i = 0; i < n; i++){\n int onesRow = 0;\n for(int j...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> result(n, vector<int>(m, 0)); \n for(int i = 0; i < n; i++){\n int onesRow = 0;\n for(int j...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n int rowadder(vector<vector<int>>& grid,int i){\n int m=grid.size();\n int n=grid[0].size();\n int sum=0;\n for(int a=0;a<n;a++){\n if(grid[i][a]==0){\n sum=sum-1;\n }\n if(grid[i][a]==1){\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n int row[n];\n int col[m];\n vector<vector<int>> ans(n,vector<int> (m,0));\n for(int i=0;i<n;i++){\n int oner...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<vector<int>> ans(grid.size(), vector<int>(grid[0].size()));\n int sz = grid[0].size();\n int col_j[sz];\n for(int col = 0; col < grid[0].size(); col++){\n int sum =...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n vector<vector<int>> diff(m, vector<int>(n));\n int row1[m], col1[n], row0[m], col0[n];\n /*\n for(int i = 0; i < m; i++){\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n vector<int> row(n);\n vector<int> col(m);\n\n for(int i=0;i<n;i++){\n int one=0;\n for(int y=0;y<m;y++){\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "#include<bits/stdc++.h>\nusing namespace std;\nauto init = []()\n{\nios::sync_with_stdio(false);\ncin.tie(0);\ncout.tie(0);\nreturn 0;\n}();\nclass Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int m=grid.size(),n=grid[0].size();\n vector<int> One_...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "#pragma GCC optimize(\"Ofast\")\n\nstatic auto _ = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\n\nclass Solution {\npublic:\n std::vector<std::vector<int>> onesMinusZeros(std::vector<std::vector<int>>& grid) {\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n \n vector<int> onesRow(m, 0);\n vector<int> onesCol(n, 0);\n \n for (int i = 0; i < m; i++) {\n for (...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n // Naive:\n // For each position (x, y) we calculate the diff[x][y] by scan to the row x and col y\n // Took: O(n * m * (m + n))\n // Observations\n // - Can we precalculate t...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n vector<int>row(n);\n vector<int>col(m);\n for(int i=0;i<n;i++){\n int count=0;\n for(int j=0;j<m;j++){\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n\n vector<int>rowOnes(m,0);\n vector<int>colOnes(n,0);\n\n for(int i=0;i<m;i++)\n {\n for(int j=0;j<n;j++)\n {...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n\n int m = grid.size();\n int n = grid[0].size();\n vector<int> rowOnes(m, 0);\n vector<int> colones(n, 0);\n \n for (int i = 0; i < m; i++) {\n for (int j = ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int m=grid.size();\n int n=grid[0].size();\n vector<int>onerow(m,0);\n vector<int>onecolumn(n,0);\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n i...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);\n int n=grid.size(),m=grid[0].size(),i,j,onesRow,onesCol,zerosRow,zerosCol; \n vector<vector<int>>ans(n,vector<int>(m,0)); \n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);\n int n=grid.size(),m=grid[0].size(),i,j,onesRow,onesCol,zerosRow,zerosCol; \n vector<vector<int>>ans(n,vector<int>(m,0)); \n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n \n vector<int>rowones(n,0);\n vector<int>rowzero(n,0);\n vector<int>colones(m,0);\n vector<int>colzero(m,0);\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "class Solution {\npublic:\n vector <vector <int>> onesMinusZeros (vector <vector <int>> & a) {\n \n int n = a.size ();\n int m = a[0].size ();\n \n vector <int> row_zero (n, 0);\n vector <int> row_one (n, 0);\n vector <int> col_zero (m, 0);\n vecto...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n \n vector<int> rone(n,0);\n vector<int> cone(m,0);\n vector<int> rzero(n,0);\n vector<int> czero(m,0);\n\n fo...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n\n vector<int> onesRow(n,0), zeroRow(n,0), onesCol(m,0), zeroCol(m,0);\n\n for(int i=0;i<n;i++) {\n for(int j=0;j<m;j++) {\...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "#pragma GCC optimize(\"Ofast,tree-vectorize\")\n#pragma GCC target(\"tune=native\")\n\nstatic auto _ = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\n\n\nclass Solution {\npublic:\n std::vector<std::vector<int>> onesMin...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx2\")\nstatic auto _ = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\n\n\nclass Solution {\npublic:\n std::vector<std::vector<int>> onesMinusZeros(std::vector<std:...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"tune=native\")\n\nstatic auto _ = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\n\n\nclass Solution {\npublic:\n std::vector<std::vector<int>> onesMinusZeros(std::ve...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n\n vector<int> Colones;\n vector<int> Rowones;\n\n for(int i=0;i<n;i++){\n int count = 0 ;\n for(int j=0;...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n vector<int> rowSum;\n vector<int> colSum;\n\n for(int i=0;i<m;i++){\n int temp_sum=0;\n for(int j=0;j<n;j++){\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n vector<int>oneRow(n,0),oneCol(m,0),zeroRow(n,0),zeroCol(m,0);\n for(int i=0;i<n;i++){\n // int oneR,oneC,zeroR,zeroC;\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n vector<int> rowSum;\n vector<int> colSum;\n\n for(int i=0;i<m;i++){\n int temp_sum=0;\n for(int j=0;j<n;j++){\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> ans(n, vector<int>(m, 0));\n vector<pair<int, int>> dpRow(n, pair<int, int>(0, 0));\n vector<pair<int, int...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<vector<int>>ans(grid.size(),vector<int>(grid[0].size(),0));\n int m=grid.size();\n int n=grid[0].size();\n vector<int>row1(m,0),row0(m,0);\n vector<int>col1(n,0),col0(n...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int r=grid.size(), c=grid[0].size();\n vector<int> r1(r), c1(c), r0(r), c0(c);\n for(int i=0;i<r;i++)\n for(auto g:grid[i])\n if(g==1)\n r1[i]++...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n }\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int r = grid.size();\n int c = grid[0].size();\n vector<int> rowone(r, 0...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int r=grid.size(), c=grid[0].size();\n vector<int> r1(r), c1(c), r0(r), c0(c);\n for(int i=0;i<r;i++)\n for(auto g:grid[i])\n if(g==1)\n r1[i]++...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<int> onesRows;\n vector<int> onesCols;\n int m = grid.size();\n int n = grid[0].size();\n\n for (int i = 0; i < m; i++) {\n int ones = 0;\n for (i...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic: \n\n int diffRow(const vector<vector<int>>& grid, int row, vector<int>& rowCache){\n if(row<rowCache.size()){\n return rowCache[row];\n }\n int diff = 0;\n for(int i = 0 ; i < grid[row].size(); i++){\n if(grid[row][i] == 1) di...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<int>onescol(grid[0].size(),0),onesrow(grid.size(),0),zerorow(grid.size(),0),zerocol(grid[0].size(),0);\n vector<vector<int>>diff(grid.size());\n for(int i=0;i<grid.size();i++){\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx2\")\nstatic auto _ = [](){\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return nullptr;\n}();\n\n\n\nclass Solution {\npublic:\n std::vector<std::vector<int>> onesMinusZeros(std::vector<std:...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<int>onerow;\n vector<int>onecol;\n vector<int>zerorow;\n vector<int>zerocol;\n for(int i=0;i<grid.size();i++)\n {\n int zero=0,one=0;\n for...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>&grid) {\n vector<int>one_row;\n vector<int>zero_row;\n vector<int>one_col;\n vector<int>zero_col;\n for(int i = 0;i<grid.size();i++){\n int cnt = 0;\n int cnt2 = 0;...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n int r1=0,c1=0,r0=0,c0=0;\n vector<int>oneRow,oneCol,zeroRow,zeroCol;\n for(int i=0;i<n;i++)\n {\n r1=0,r0=0;\n...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<int> r1;\n vector<int> r0;\n vector<int> c1;\n vector<int> c0;\n int m=grid.size(), n=grid[0].size();\n int count = 0;\n for(int i=0; i<m; i++) {\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<int> onesRowi,onesColj,zerosRowi,zerosColj; \n int n = grid.size(), m = grid[0].size();\n for (int i = 0 ; i<n ; ++i)\n {\n onesRowi.push_back(accumulate(grid[i].b...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n // Fast I/O\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n \n // Code\n int m = grid.size();\n int n = grid[0].size();\n\n vect...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n vector<pair<int,int>>ans1,ans2;\n for(int i=0;i<n;i++){\n int rowzeroes=0;\n int rowones=0;\n for(int j=...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<pair<int,int>> row;\n vector<pair<int,int>> col;\n for(int i=0;i<grid.size();i++){\n int zero=0, one=0;\n for(int j=0;j<grid[0].size();j++){\n if...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "auto init = [](){\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<int> orow;\n vector<int> ocol;\n vector<int> zrow;\n vector<int> zco...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<vector<int>> diff; \n const size_t M = grid.size();\n const size_t N = grid[0].size();\n for(size_t i = 0; i < M; ++i){\n diff.push_back(vector(N, 0));\n }\n...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<int> onesRow,onesCol;\n for(int i=0;i<grid.size();i++){\n int sum=0;\n for(int j=0;j<grid[0].size();j++){\n sum+=grid[i][j];\n }\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<int> oneRow,oneCol;\n int rows=grid.size(),cols=grid[0].size();\n for(int i=0;i<rows;i++)\n oneRow.push_back(count1(grid[i]));\n for(int i=0;i<grid[0].size();i++){\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<int> diffRow;\n vector<int> diffCol;\n\n for (int i = 0; i != grid.size(); ++i) {\n int tmp = 0;\n for (int j = 0; j != grid[i].size(); ++j) {\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<vector<int>> mat=grid;\n int n=grid.size();\n int m=grid[0].size();\n for(int i=0;i<m;i++){\n int c=0;\n for(int j=0;j<n;j++){\n if(grid[j...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<vector<int>>diff(grid);\n map<int,int>m;\n for(int i=0;i<grid.size();i++)\n {\n int oi=0;\n for(int a=0;a<grid[0].size();a++)\n {\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<vector<int>>diff(grid);\n map<int,int>m;\n for(int i=0;i<grid.size();i++)\n {\n int oi=0;\n for(int a=0;a<grid[0].size();a++)\n {\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n vector<vector<int>>diff(grid);\n map<int,int>m;\n for(int i=0;i<grid.size();i++)\n {\n int oi=0;\n for(int a=0;a<grid[0].size();a++)\n {\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n\n int m=grid.size();\n int n=grid[0].size();\n if(m==1&&n==1){\n if(grid[0][0]==1){\n return{{2}};\n }\n else{\n return {{-2}}...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "#define MAXROWS 100000\n#define MAXCOLS 100000\nclass Solution {\npublic:\n\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n if (grid.size() == 0) return grid;\n \n vector<int> *rowOnes1 = new vector<int>;\n vector<int> *colOnes1 = new vector<int>(grid[0].s...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "#define MAXROWS 100000\n#define MAXCOLS 100000\nclass Solution {\npublic:\n\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n if (grid.size() == 0) return grid;\n \n vector<int> *rowOnes1 = new vector<int>;\n vector<int> *colOnes1 = new vector<int>(grid[0].s...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "#define MAXROWS 100000\n#define MAXCOLS 100000\nclass Solution {\npublic:\n\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n if (grid.size() == 0) return grid;\n \n vector<int> *rowOnes1 = new vector<int>;\n vector<int> *colOnes1 = new vector<int>(grid[0].s...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\n int RowColSum(int row, int col, vector<vector<int>> grid) {\n int sum_one = 0;\n int sum_zero = 0;\n for (int i = 0; i < grid[0].size(); i++) {\n if (grid[row][i] == 0)\n sum_zero += 1;\n else\n sum_one += 1;\n ...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int rs=grid.size();\n int cs=grid[0].size();\n vector<int> arr(rs);\n vector<int> arr1(cs);\n vector<vector<int>> mat(rs,vector<int>(cs));\n int i,j;\n for(i=0;i...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int rs=grid.size();\n int cs=grid[0].size();\n vector<int> arr(rs);\n vector<int> arr1(cs);\n vector<vector<int>> mat(rs,vector<int>(cs));\n int i,j;\n for(i=0;i...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int m=grid.size(), n=grid[0].size();\n\n vector<vector<int>>diff(m, vector<int>(n,0));\n\n vector<int>rowones(m,0), colones(n,0);\n\n for(int i=0; i<m; i++){\n for(int j=0...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int rows=grid.size();\n int cols=grid[0].size();\n\n vector<vector<int>> ans;\n\n vector<int> rowsum1;\n vector<int> rowsum0;\n vector<int> colsum1;\n vector<int...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int rows=grid.size();\n int cols=grid[0].size();\n\n vector<vector<int>> ans;\n\n vector<int> rowsum1;\n vector<int> rowsum0;\n vector<int> colsum1;\n vector<int...
2,606
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> binary matrix <code>grid</code>.</p> <p>A <strong>0-indexed</strong> <code>m x n</code> difference matrix <code>diff</code> is created with the following procedure:</p> <ul> <li>Let the number of ones in the <code>i<sup>th</sup></code> row be <code>one...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> onesMinusZeros(vector<vector<int>>& grid) {\n int rows=grid.size();\n int cols=grid[0].size();\n\n vector<vector<int>> ans;\n\n vector<int> rowsum1;\n vector<int> rowsum0;\n vector<int> colsum1;\n vector<int...