id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m=mat.size(),n=mat[0].size();\n vector<vector<int>>vis(m,vector<int>(n,-1));\n queue<pair<int,int>>q;\n for(int i=0;i<m;i++)\n {\n for(int j=0;j<n;j++)\n ... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m=mat.size();\n int n=mat[0].size();\n vector<vector<int>> dist(m,vector<int>(n,INT_MAX));\n queue<pair<int,int>> q;\n for (int i=0;i<m;i++){\n for (int j=0;j<n;j+... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m=mat.size();\n int n=mat[0].size();\n vector<vector<int>> dist(m,vector<int>(n,INT_MAX));\n queue<pair<int,int>> q;\n for (int i=0;i<m;i++){\n for (int j=0;j<n;j+... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\nmap<pair<int,int>,int> multibfs(vector<pair<int,int>> start,vector<vector<int>>& grid)\n {\n map<pair<int,int>,int> dist;\n queue<pair<int,int>> q;\n int i,j,n,m;\n n = grid.size();\n m = grid[0].size();\n for(i=0;i<n;i++)\n {\... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "vector<int> dr = {0 , -1 , 0 , 1};\nvector<int> dc = {-1 , 0 , 1 , 0};\n\nclass Solution {\npublic:\n // int bfs(vector<vector<int>>& mat,int frow,int fcol){\n // int m=mat.size(),n=mat[0].size();\n // vector<vector<int>> vis(m , vector<int>(n , 0));\n // vis[frow][fcol] = 1;\n /... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m = mat.size();\n int n = mat[0].size();\n\n vector<vector<int>> visited(m, vector<int> (n,0));\n vector<vector<int>> res(m, vector<int> (n,0));\n queue<pair<int,int>> q;\n\n... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n queue<pair<int,int>> q;\n int m=mat.size(),n = mat[0].size();\n vector<vector<int>> ans(m,vector<int>(n,1e5));\n vector<vector<int>> vis(m,vector<int>(n,0));\n for (int i=0;i<m;i... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size(); \n vector<vector<bool>> visited(n, vector<bool>(m, false));\n queue<pair<pair<int, int>, int>> q;\n\n for(int i = 0; i < n; i++) {\n ... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size(); \n vector<vector<bool>> visited(n, vector<bool>(m, false));\n queue<pair<pair<int, int>, int>> q;\n\n for(int i = 0; i < n; i++) {\n ... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n /*\n Given:\n mat: Array of binary digits\n 1 <= M, N <= 1E4\n 1 <= M*N <= 1E4\n Exist i,j s.t. mat[i][j] = 0 \n\n Return:\n Matrix of same size, res[i][j] = distance to closest 0 from... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n int m, n;\n vector<vector<int>> dp;\n \n void bfs(vector<pair<int, int>>& mp){\n queue<pair<int, int>> q;\n set<pair<int, int>> st;\n vector<pair<int, int>> dir {{1,0},{-1,0},{0,1},{0,-1}};\n \n for(auto i: mp){\n q.push(... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\n \npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m=mat.size();\n int n=mat[0].size();\n queue<pair<pair<int,int>,int>>q;\n vector<vector<int>>vis(m,vector<int>(n));\n for(int i=0;i<m;i++){\n for(int j=... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\n \npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m=mat.size();\n int n=mat[0].size();\n queue<pair<pair<int,int>,int>>q;\n vector<vector<int>>vis(m,vector<int>(n));\n for(int i=0;i<m;i++){\n for(int j=... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m = mat.size(), n = mat[0].size();\n vector<vector<int>> dis(m, vector<int>(n, 0)), vis(m, vector<int>(n, -1));\n queue<pair<int, pair<int, int>>> q;\n for(int i=0; i<m; i++) {\n ... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\n int m, n;\n bool valid(int r, int c){\n return r>=0 && r<m && c>=0 && c<n;\n }\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n m = mat.size(), n = mat[0].size();\n vector<vector<int>>res(m, vector<int>(n, INT_MAX));\n dequ... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> visited;\n void bfsmulti(vector<vector<int>>mat,vector<vector<int>>& output,vector<pair<int,int>> source)\n {\n queue <pair<pair<int,int>,int>> q; \n for(auto[x,y]:source)\n {\n q.push({{x,y},0});\n visited[x][y]=1;\n }\n... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m=mat.size();\n int n=mat[0].size();\n queue<vector<int>>q;\n // vector<vector<bool>> vis(m,vector<bool>(n));\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n ... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n size_t m = mat.size();\n size_t n = mat[0].size();\n \n queue<vector<int>> currLevel;\n \n for(int i=0; i<m; i++){\n for(int j=0; j<n; j++){\n if... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m = mat.size();\n int n = mat[0].size();\n vector<vector<int>>ans(n,vector<int>(m,0));\n\n queue<pair<int,pair<int,int>>> q;\n vector<vector<bool>> vis (m,vector<bool>(n,false));\n\n fo... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m = mat.size();\n int n = mat[0].size();\n vector<vector<int>>ans(n,vector<int>(m,0));\n\n queue<pair<int,pair<int,int>>> q;\n vector<vector<bool>> vis (m,vector<bool>(n,false));\n\n fo... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n return getUpdatedMatrix(mat);\n }\n\n vector<vector<int>> getUpdatedMatrix(vector<vector<int>>& mat)\n {\n // vector<vector<int>> ansMat(mat.size(), vector<int>(mat[0].size(), 0));\n v... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\nbool isvalid(int x,int y,int n,int m){\n if((x>=0 && x<n) && (y>=0 && y<m))return true;\n return false;\n}\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int n=mat.size(),m=mat[0].size();\n int INF=1000000;\n vector<vector<int>>vis(... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int m=mat.size();\n int n=mat[0].size();\n queue<vector<int>>q;\n vector<vector<bool>> vis(m,vector<bool>(n));\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n ... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\npublic:\n int m;\n int n;\n vector<vector<int>> directions = {{0,1}, {0,-1}, {1,0}, {-1, 0}};\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n m = mat.size();\n n = mat[0].size();\n vector<vector<int>> matrix(m, vector<int>(n, 0));\n ... |
542 | <p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>
<p>The distance between two adjacent cells is <code>1</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetc... | 3 | {
"code": "class Solution {\n\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n int dirs[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};\n int m = mat.size();\n int n = mat[0].size();\n vector<vector<int>> matrix(m, vector<int>(n, 0));\n vector<vector<bool>> seen(m, ... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 0 | {
"code": "\nclass Solution {\npublic:\n int levels(TreeNode*root){\n if(root==NULL)return 0;\n return 1 + max(levels(root->left),levels(root->right));\n}\n void helper(TreeNode*root, int &maxDia){\n if(root==NULL)return;\n int ans = levels(root->left)+levels(root->right);\n maxDia =... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 1 | {
"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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 1 | {
"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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
543 | <p>Given the <code>root</code> of a binary tree, return <em>the length of the <strong>diameter</strong> of the tree</em>.</p>
<p>The <strong>diameter</strong> of a binary tree is the <strong>length</strong> of the longest path between any two nodes in a tree. This path may or may not pass through the <code>root</code>... | 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... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 0 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n int n = s.size();\n bool flag = false;\n int count_a = 0, count_l = 0;\n for(int i = 0; i < n; i++) {\n if(s[i] == 'P') {\n flag = true;\n if(count_l > 0)\n ... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 0 | {
"code": "class Solution\n{\npublic:\n bool checkRecord(string s)\n {\n int x = 0;\n int y = 0;\n for (int i = 0; i < s.size(); i++)\n {\n if (s[i] == 'A')\n {\n x++;\n }\n else if (s[i] == 'L')\n {\n ... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 0 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) \n {\n int countL = 0;\n int numA = 0;\n for(int i = 0; i < s.size(); ++i)\n {\n if(s[i] == 'P')\n {\n countL = 0;\n continue;\n }\n else if(s[i... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 0 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n int count1=0;\n int count2=0;\n for(int i=0;i<s.size();i++){\n if(s[i]=='A'){\n count1++;\n if(count2<3){\n count2=0;\n } \n }\n ... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 0 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n int absent=0;\n int late=0;\n for(int i=0;i<s.length();i++){\n if(s[i]=='A'){\n absent++;\n }\n if(s[i]=='L'){\n if(s[i]==s[i+1]){\n if(s[i+1]==s[i+2]){\n late=1;\n }\n ... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 0 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n int ab = 0;\n int late = 0;\n\n for (int i = 0; i < s.size(); i++){\n char now = s[i];\n if (now == 'A'){\n ab += 1;\n }\n if (now == 'L'){\n late += ... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 0 | {
"code": "class Solution {\n public:\n bool checkRecord(string s) {\n int countA = 0;\n int countL = 0;\n\n for (const char c : s) {\n if (c == 'A' && ++countA > 1)\n return false;\n if (c != 'L')\n countL = 0;\n else if (++countL > 2)\n return false;\n }\n\n retur... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 2 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n int count1=0;\n int count2=0;\n for(int i=0;i<s.size();i++){\n if(s[i]=='A'){\n count1++;\n if(count2<3){\n count2=0;\n } \n }\n ... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 2 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n bool temp=true;\n int i=0;\n int count=0, count1=0;\n while(i<s.size())\n {\n if(s[i]=='A')\n {\n count++;\n }\n if(s[i]=='L')\n {\n ... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 3 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n int absent = 0;\n int maxi = INT_MIN;\n int late = 0;\n for(auto c : s){\n if(c == 'L') late++;\n else late = 0;\n if(c=='A') absent++;\n maxi = max(maxi,late);\n }\n... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 3 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n \n\n string s1=s;\n\n sort(s1.begin(),s1.end());\n\n\n if(s1[0]=='A' && s1[1]=='A')return false;\n\n string check=\"LLL\";\n\n if(s.size()>=3){\n for (int i = 0; i <=s.size()-3; ++i)\n {\n str... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 3 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n unordered_map<char,int>map;int n=0;\n for(char c:s) {\n map[c]++;\n if(c == 'L') n++;\n else n=0;\n if(n >=3) return false;\n if(c=='A' && map[c]>=2) return false;\n }\n... |
551 | <p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>
<ul>
<li><code>'A'</code>: Absent.</li>
<li><code>'L'</cod... | 3 | {
"code": "class Solution {\npublic:\n bool checkRecord(string s) {\n int n = s.size();\n vector<vector<int>> dp(2, vector<int>(n, 0));\n if (s[0] == 'A')\n dp[0][0] = 1;\n if (s[0] == 'L')\n dp[1][0] = 1;\n for (int i = 1; i < n; i++) {\n if (s[i... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 0 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n int si=0,ei=s.length()-1;\n int sit=0,eit=t.length()-1;\n\n while(sit<=eit && si<=ei){\n // cout<<sit<<eit<<endl;\n // cout<<si<<ei<<endl;\n if(s[si]==t[sit]){\n ... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 0 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n size_t pos = 0;\n for(char c : s){\n pos = t.find(c, pos);\n if(pos == string::npos){\n return false;\n }\n pos++;\n }\n return true;\n }\n};",... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 0 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n int n = s.length();\n int m = t.length();\n\n int i =0; \n int j = 0;\n\n while(i<n && j<m){\n if(s[i] == t[j]){\n i++;\n }\n j++;\n }\n\n ... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 0 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n int i = 0;\n int j = 0;\n while (i < s.size() && j < t.size()) {\n if (s[i] == t[j]) {\n i++;\n }\n j++;\n }\n return s.size() == i;\n }\n};",
"m... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 0 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n int foundpos = 0;\n bool found = false;\n for(int i=0; i<s.size(); i++){\n found = false;\n for(int p = foundpos; p<t.size(); p++){\n if(s[i] == t[p]){\n fo... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 0 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n int lenS = s.size();\n int lenT = t.size();\n int i=0,j=0;\n while(i < lenS && j < lenT)\n {\n if(s[i] == t[j])\n {\n i++;\n }\n j++;\n ... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 0 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n int sLen = s.length();\n int tLen = t.length();\n\n int i = 0, j = 0;\n\n while(i < sLen && j < tLen){\n if(s[i] == t[j]){\n i++;\n }\n j++;\n }\n\n ... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 0 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n size_t idx = 0;\n for(char i:s)\n { \n idx = t.find(i,idx);\n if(idx!= std::string::npos)\n {\n idx+=1;\n }\n else return false;\n }\... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 1 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n\n int j = 0, i = 0;\n\n while (i < t.length()){\n if (t[i] == s[j]){\n i++;\n j++;\n if (j == s.size()){\n return true;\n }\n ... |
392 | <p>Given two strings <code>s</code> and <code>t</code>, return <code>true</code><em> if </em><code>s</code><em> is a <strong>subsequence</strong> of </em><code>t</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
<p>A <strong>subsequence</strong> of a string is a new string that is formed from the original... | 3 | {
"code": "class Solution {\npublic:\n bool isSubsequence(string s, string t) {\n int n = s.length();\n int m = t.length();\n if(n>m){\n return false;\n }\n if(m==0&&n!=0){\n return false;\n }\n if(n==0&&m!=0){\n return true;\n ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 0 | {
"code": "class Solution{\npublic:\n bool validUtf8(vector<int> &data){\n int n = data.size(); \n int count = 0; \n for (int i = 0; i < n; i++){ \n int ele = data[i]; \n if (!count){ \n\t // if the first 3 bits are 110, then the next byte is part of the current UTF-8 character\n ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 0 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data) {\n \n \n int n=data.size();\n \n int count=0;\n \n \n for(int i=0;i<n;i++){\n \n int elem=data[i];\n \n \n if(!count){\n ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 0 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data) {\n int c=0;\n for(auto it: data){\n if(c==0){\n if((it>>5)==0b110) c=1;\n else if((it>>4)==0b1110) c=2;\n else if((it>>3)==0b11110) c=3;\n else if((it>>7)) ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 0 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data) {\n int n = data.size();\n for (int i = 0; i < n; ) {\n if (data[i] >= 0 && data[i] <= 127) { // 1-byte character\n ++i;\n } else if (data[i] >= 192 && data[i] <= 223) { // 2-byte character\n... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 0 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data) {\n int currData = 0;\n\n for(int i=0; i<data.size(); i++){\n if(currData){\n if((data[i] >> 6) != 0b10){\n return false;\n }\n currData--;\n ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 2 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data) {\n int c=0;\n for(auto a:data) {\n if ((a&(0b10000000))==0) {\n if (c) return false;\n } else if ((a&0b11100000)==0b11000000) {\n if (c) return false;\n c=1;\n ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 2 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data) {\n int i = 0;\n\n while (i < data.size()) {\n if ((0b10000000 & data[i]) == 0b00000000) {\n i++;\n } else if ((0b11100000 & data[i]) == 0b11000000) {\n if (data.size() >= i + ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data) {\n int n = data.size();\n int remainBytes = 0;\n int i = 0;\n while(i < n) {\n int& cur = data[i];\n if(remainBytes == 0) {\n printf(\"check: %d %d %d %d %d\\n\", cur&128, cur&... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n\ntemplate <std::size_t ...I>\nbool validateImpl(const std::vector<int> &str, size_t i, std::index_sequence<I...>)\n{\n return ((std::countl_one((uint8_t)str[i+I]) == 1) and ...);\n}\n\ntemplate <std::size_t Count>\nbool validate(std::vector<int> &str, size_t i)\n{\n return... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n\nbool validate(const std::vector<int> &str, size_t i, size_t count)\n{\n for (; count > 0; --count, ++i) { \n if (std::countl_one((uint8_t)str[i]) != 1)\n return false;\n }\n return true; \n}\n\n\n\nbool validUtf8(std::vector<int> str)\n{\n for (siz... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n\nbool validate(const std::vector<int> &str, size_t i, size_t count)\n{\n for (; count > 0; --count, ++i) { \n if (std::countl_one((uint8_t)str[i]) != 1)\n return false;\n }\n return true; \n}\n\nbool validUtf8(std::vector<int> str)\n{\n for (size_t ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data, int i = 0) {\n if(i >= data.size()){\n return true;\n }\n for(int j = 7; j >= 3; j--){\n if((data[i]&(1<<j)) == 0){\n if(j == 6){\n return false;\n }\... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n\n string solve(int data){\n string ans = \"\";\n for(int i=0;i<8;i++){\n if((data & (1 << i)) != 0){\n ans += '1';\n }\n else {\n ans += '0';\n }\n }\n reverse(ans.begin(), a... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n\n string solve(int data){\n string ans = \"\";\n for(int i=0;i<8;i++){\n if((data & (1 << i)) != 0){\n ans += '1';\n }\n else {\n ans += '0';\n }\n }\n reverse(ans.begin(), a... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n bool is_valid(vector<int>sub_part){\n for(auto it:sub_part){\n if((it>>7 & 1) && !(it>>6 & 1))\n continue;\n else \n return false;\n }\n return true;\n }\n bool validUtf8(vector<int>& data) {\n ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n vector<int> valid;\n bool tryn(int ind, vector<int> &data, int n){\n //int mask = 0;\n for(int i = 0; i<n; ++i){\n if(!(data[ind] & (1 << (7-i)))){\n //cout << \"FIRSTNUM1 FAILED\\n\";\n return false;\n }\n ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n vector<int> valid;\n bool tryn(int ind, vector<int> &data, int n){\n //int mask = 0;\n for(int i = 0; i<n; ++i){\n if(!(data[ind] & (1 << (7-i)))){\n cout << \"FIRSTNUM1 FAILED\\n\";\n return false;\n }\n ... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\nstring decToBin(int dec){\n string ans = \"\";\n\n while(dec){\n int rem = dec%2;\n int q = dec/2;\n dec = q;\n if(rem == 1)\n ans = \"1\" + ans;\n else ans = \"0\" + ans;\n }\n while(ans.size() < 8){\n ans = \"0\" + a... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\nstring decToBin(int dec){\n string ans = \"\";\n\n while(dec){\n int rem = dec%2;\n int q = dec/2;\n dec = q;\n if(rem == 1)\n ans = \"1\" + ans;\n else ans = \"0\" + ans;\n }\n while(ans.size() < 8){\n ans = \"0\" + a... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\nstring decToBin(int dec){\n string ans = \"\";\n\n while(dec){\n int rem = dec%2;\n int q = dec/2;\n dec = q;\n if(rem == 1)\n ans = \"1\" + ans;\n else ans = \"0\" + ans;\n }\n while(ans.size() < 8){\n ans = \"0\" + a... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data) {\n vector<string> a(data.size());\n int n = data.size();\n \n\t\t// Converting all the numbers into binary and storing in array as string\n for(int i=0; i<n; i++){\n while(data[i]){\n a[i... |
393 | <p>Given an integer array <code>data</code> representing the data, return whether it is a valid <strong>UTF-8</strong> encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).</p>
<p>A character in <strong>UTF8</strong> can be from <strong>1 to 4 bytes</strong> long, subjected to the following ru... | 3 | {
"code": "class Solution {\npublic:\n bool validUtf8(vector<int>& data) {\n int n = data.size();\n\n auto validSuffix = [&](int at) {\n return at < n && data[at] >> 6 == 0b10;\n };\n\n function<bool(int)> valid = [&](int i) {\n if (i == n)\n return ... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n string result = \"\";\n \n for(int i=0;i<s.size();i++){\n if(s[i] != ']'){\n result.push_back(s[i]);\n }\n else{\n string str = \"\";\n while(!... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<string> chars;\n stack<int> nums;\n string answer;\n int num = 0;\n for(char c : s) {\n if(isdigit(c)) {\n num = num*10 + c-'0';\n }\n else if(c=='[') {\... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> m;\n for(char c : s){\n if(c==']'){\n string decoded = \"\";\n while(m.top()!='['){\n decoded += m.top();\n m.pop();\n }\n... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n bool isDig(char c) {\n return c>='0' && c<='9';\n }\n bool isAlpha(char c) {\n return c>='a' && c<='z';\n }\n string f(string &s, int &i) {\n int op = 0;\n string ans = \"\";\n while(i<s.size() && isAlpha(s[i])) ans+=s[i++];\n ... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n string res;\n for(int i=0;i<s.size();i++){\n if(s[i]!=']'){\n res.push_back(s[i]);\n }else{\n string str;\n int j=res.size()-1;\n while(!res.empty... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<char> st;\n\n for(auto i:s){\n \n if(i==']'){\n\n string temp=\"\";\n while(st.top()!='['){\n temp+=st.top();\n st.pop();\n ... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n int index=0;\n return decode(s, index);\n }\n string decode(const string& s, int& index) {//IMP int&\n string result;\n while (index < s.length() && s[index] != ']') {\n if (!isdigit(s[index]))//ag... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<int> counts;\n stack<string> result;\n string current = \"\";\n int i = 0;\n while (i < s.length()) {\n if (isdigit(s[i])) {\n int count = 0;\n while (isdigit(s... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n int n = s.size();\n stack<string> st;\n stack<int> num;\n string currentStr = \"\";\n int i = 0;\n\n while (i < n) {\n if (isdigit(s[i])) {\n int count = 0;\n ... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 0 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<int> num; \n stack<string> ch; // Changed to stack<string> to handle nested strings\n string decoded = \"\";\n int count = 0; // To handle numbers greater than 9\n\n for (int i = 0; i < s.size(); i++... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 2 | {
"code": "class Solution {\npublic:\n string decodeString(string s) {\n stack<string> st;\n st.push(\"\");\n int num = 0;\n\n for (char c : s) {\n if (c == '[') {\n st.push(to_string(num));\n st.push(\"\");\n num = 0;\n ... |
394 | <p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume th... | 2 | {
"code": "class Solution {\npublic:\n bool isDigit(string ch) {\n if(ch == \"0\" || ch == \"1\" || ch == \"2\" || ch == \"3\" || ch == \"4\" || ch == \"5\"\n || ch == \"6\" || ch == \"7\" || ch == \"8\" || ch == \"9\")\n return true;\n return false;\n }\n string decodeStrin... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.