id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector<vector<int>>& obs) {\n int i, j, n = obs.size(), m = obs[0].size();\n int tp[n][m];\n if (obs[0][0] == 1)\n return 0;\n\n tp[0][0] = 1;\n\n for (i = 1; i < n; i++) {\n if (obs[i][0] =... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n if (grid[0][0])\n return 0;\n\n vector<vector<int>> dp(m, vector<int>(n, 0));\n int flag = 0;\n for (int i = 0; i ... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n int m = obstacleGrid.size();\n int n = obstacleGrid[0].size();\n obstacleGrid[0][0] = (obstacleGrid[0][0] == 1) ? 0 : -1;\n for (int i = 0; i < m; i++) {\n for (int j = ... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\npublic:\n \n int isPossible(int i,int j, int m, int n,int obst){\n if(i>=0&&i<m&&j>=0&&j<n&&!obst){\n return 1; \n }\n return 0;\n }\n\n \n int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n int m=obstacleGrid.size();\... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector<vector<int>>& ob) {\n int m=ob.size(),n=ob[0].size();\n cout<<n<<\" \"<<m;\n if(ob[m-1][n-1]==1 || ob[0][0]==1) return 0;\n if(m==1 && n==1 && ob[0][0]==0) return 1;\n for(int i=1;i<m;i++){\n if(... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\n int solve(vector<vector<int>>& obstacleGrid,int i,int j,vector<vector<int>> &dp)\n {\n if(i>=0 and j>=0 and obstacleGrid[i][j]==1) //stone / obstacle found\n {\n return 0;\n }\n if(i<0 or j<0) //out of bound\n {\n return 0;\n... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 0 | {
"code": "class Solution {\npublic:\nint solve(int i,int j,int m,int n,vector<vector<int>>& obstacleGrid, vector<vector<int>> &dp){\n if(i>=m||j>=n){\n return 0;\n }\n if(obstacleGrid[i][j]==1)\n {\n return 0;\n }\n if(i==m-1&&j==n-1){\n return 1;\n }\n if(dp[i][j]!=-1){... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 1 | {
"code": "class Solution {\npublic:\n int fn(int i, int j, vector<vector<int>>& v, vector<vector<int>>&dp){\n //base case\n if(i==0 && j==0)return 1; //reached 1st cell means valid way\n if(dp[i][j]!=-1)return dp[i][j];\n \n int up=0, left=0;\n \n //move up\n ... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 1 | {
"code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n int m = obstacleGrid.size();\n int n = obstacleGrid[0].size();\n if(obstacleGrid[0][0]) return 0;\n vector<vector<int>> dp(m,vector<int>(n,-1));\n for(int i = 0;i<m;i++)\n ... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 2 | {
"code": "class Solution {\npublic:\n int uniquePathsWithObstacles(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n if(grid[0][0] == 1 || grid[m-1][n-1]==1) return 0;\n if(m==1 && n==1) return 1;\n vector<vector<long long>> dp(m, vector<long long>(... |
63 | <p>You are given an <code>m x n</code> integer array <code>grid</code>. There is a robot initially located at the <b>top-left corner</b> (i.e., <code>grid[0][0]</code>). The robot tries to move to the <strong>bottom-right corner</strong> (i.e., <code>grid[m - 1][n - 1]</code>). The robot can only move either down or ri... | 2 | {
"code": "class Solution {\n public:\n int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {\n const int m = obstacleGrid.size();\n const int n = obstacleGrid[0].size();\n // dp[i][j] := the number of unique paths from (0, 0) to (i, j)\n vector<vector<long>> dp(m + 1, vector<long>(n + 1, 0))... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\n public:\n int minPathSum(vector<vector<int>>& grid) {\n const int m = grid.size();\n const int n = grid[0].size();\n\n for (int i = 0; i < m; ++i)\n for (int j = 0; j < n; ++j)\n if (i > 0 && j > 0)\n grid[i][j] += min(grid[i - 1][j], grid[i][j - 1]);\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n\n vector<vector<int>>& dp = grid;\n dp[0][0] = grid[0][0];\n\n for (int i = 1; i < n; i++) dp[0][i] = grid[0][i] + dp[0][i - 1];\n for (int... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n\n vector<vector<int>>& dp = grid;\n\n for (int i = 1; i < n; i++) dp[0][i] = grid[0][i] + dp[0][i - 1];\n for (int j = 1; j < m; j++) dp[j][0] = g... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int max_row = grid.size(), max_col = grid[0].size();\n\n\n for (int c = 1; c < max_col; ++c)\n {\n grid[0][c] += grid[0][c - 1];\n }\n \n for (int r = 1; r < max_row; ++r)\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int _n=grid.size();\n int _m=grid[0].size();\n for(int i=0;i<_n;i++){\n for(int j=0;j<_m;j++){\n int top=(i-1<0)? INT_MAX:grid[i-1][j];\n int bottom=j-1<0? INT_MAX : g... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n\n for (int i = 1; i < m; i++){\n grid[i][0] += grid[i-1][0];\n }\n for (int i = 1; i < n; i++){\n grid[0][i] += grid[0][i-1];\n }\... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "using vi = vector<int>;\nusing vii = vector<vi>;\n\nclass Solution {\n\n const int INF = 987654321;\n\npublic:\n int minPathSum(vector<vector<int>>& grid);\n // int findMinPath(vii &grid, int MSIZE, int NSIZE, int m, int n);\n};\n\nint Solution::minPathSum(vector<vector<int>>& grid) {\n\n // 입력... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n\n int minPathSum(vector<vector<int>>& grid) {\n \n int row = grid.size();\n int col = grid[0].size();\n\n vector<int>dp(col,0);\n\n for(int i=0 ; i<row ; i++)\n {\n int temp=0;\n\n for(int j=0 ; j<col ; j++)\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n\n vector<int> prev(n, -1);\n vector<int> curr(n, -1);\n curr[n-1] = grid[m-1][n-1];\n\n for(int i=m-1; i>=0; i--){\n for(int j=n-1; j>=0; j--... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int dp[200][200];\n int solve(vector<vector<int>>& grid, int x , int y, int m ,int n){\n if(x <0 || x > m || y>n || y<0){\n return 0;\n }\n if(dp[x][y] >0){\n return dp[x][y];\n }\n cout<< x << \" \"<< y ;\n i... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int r = grid.size(), c = grid[0].size(),dp[r][c];\n for(int i=0;i<r;i++){\n for(int j=0;j<c;j++){\n if(i==0&&j==0){\n dp[i][j] = grid[i][j];\n }\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n int f[m][n];\n f[0][0] = grid[0][0];\n for (int i = 1; i < m; ++i) {\n f[i][0] = f[i - 1][0] + grid[i][0];\n }\n for (int j = 1; j < n... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\n int dp[201][201];\npublic:\n\n int helper(int i , int j , int n, int m, vector<vector<int>> &grid){\n if (i == n-1 && j == m-1){\n return grid[i][j];\n }\n if (i >= n || j>= m)return 100000;\n if (dp[i][j] != -1) return dp[i][j];\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\nint solve(int i,int j,vector<vector<int>>& grid,vector<vector<int>>& dp){\n if(i==0&&j==0)return grid[0][0];\n if(i<0||j<0)return INT_MAX;\n // if(dp[i][j]!=-1)return dp[i][j];\n int up=solve(i-1,j, grid,dp);\n int left=solve(i,j-1, grid,dp);\n // return dp[i][j... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m = grid.size(), n=grid[0].size();\n vector<vector<int>> res(m, vector<int>(n, 0));\n for(int i=0;i<m;i++) {\n for(int j=0;j<n;j++) {\n if (i==0 && j==0) {\n re... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "\nclass Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n if (grid.empty() || grid[0].empty()) {\n return 0;\n }\n \n int m = grid.size();\n int n = grid[0].size();\n vector<vector<int>> t(m, vector<int>(n, 0));\n \n t[0][0] = grid[0][0];\n \n for (i... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n vector<int> prev(n,INT_MAX);\n for(int i =0;i<m;i++){\n vector<int> temp(n,INT_MAX);\n for(int j = 0;j<n;j++){\n if(... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 1 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n //Tabulation\n int row = grid.size(), col = grid[0].size();\n vector<vector<int>> dp(row,vector<int> (col,-1));\n for(int i=0;i<row;i++){\n for(int j=0;j<col;j++){\n if(i==0 &&... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 1 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n //Tabulation\n int row = grid.size(), col = grid[0].size();\n vector<vector<int>> dp(row,vector<int> (col,-1));\n for(int i=0;i<row;i++){\n for(int j=0;j<col;j++){\n if(i==0 &&... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\nint f(int r,int c,vector<vector<int>>& grid,vector<vector<int>> &dp){\n if(r<0||c<0)return 9999999999;\n if(r==0&&c==0)return grid[0][0];\n if(dp[r][c]!=-1)return dp[r][c];\n int left=f(r-1,c,grid,dp)+grid[r][c];\n int up=f(r,c-1,grid,dp)+grid[r][c];\n return dp... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n void miniPath(vector<vector<int>>& grid,int x,int y,vector<vector<int>>& ans){\n if(x>=grid.size() || y>=grid[0].size()){\n return;\n }\n if(x==grid.size()-1 && y==grid[0].size()-1){\n ans[x][y]=grid[x][y];\n return;\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\nvector<pair<int,int>> movements = {{0,1},{1,0}};\n bool isvalid(int i, int j, int m, int n){\n if(i>=m || j>=n || i<0 || j<0)return false;\n return true;\n }\n long long int func(vector<vector<int> > &grid, int m , int n,vector<vector<int> > &dp){\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<long long int>>dp;\n int minPathSum(vector<vector<int>>& grid) {\n dp=vector<vector<long long int>>(grid.size(),vector<long long int>(grid[0].size(),-1));\n\n return ans1(0,0,grid);\n \n }\n\n // vector<int>dir{1,0,-1,0,1}\n long... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\nprivate:\n int fun(int i, int j, vector<vector<int>>&grid,vector<vector<int>>&dp)\n {\n if(i == 0 && j == 0)\n {\n //src cell, we know the answer for this cell\n dp[0][0] = grid[0][0];\n return dp[0][0];\n }\n if( i < 0 ||... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\nprivate:\n int fun(int i, int j, vector<vector<int>>&grid,vector<vector<int>>&dp)\n {\n if(i == 0 && j == 0)\n {\n //src cell, we know the answer for this cell\n dp[0][0] = grid[0][0];\n return dp[0][0];\n }\n if( i < 0 ||... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\nint f(int r,int c,vector<vector<int>>&a,vector<vector<int>>&dp){\n // if(r==0&&c==0)\n // return dp[r][c]=a[0][0];\n // if(r<0||c<0)\n // return 1e9;\n // if(dp[r][c]!=-1)\n // return dp[r][c];\n // int up=a[r][c]+f(r-1,c,a,dp... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int solve(int row, int col, int sum, int rows, int cols,\n vector<vector<int>>& grid, vector<vector<int>>& visited, vector<vector<int>>& dp) {\n if (row < 0 || row >= rows || col < 0 || col >= cols ||\n visited[row][col] == 1) {\n ret... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\nint fun(vector<vector<int>>& grid,int i,int j,vector<vector<int>>&dp)\n{\n int m=grid.size();\n int n=grid[0].size();\n if(dp[i][j]!=-1)\n return dp[i][j];\nif(i==m-1&&j==n-1)\nreturn grid[i][j];\n\n int l=INT_MAX,d=INT_MAX;\n if(j<n-1)\n l=fun(grid,i,j+1,dp)+... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n long long rohit(int i,int j,int m,int n,vector<vector<int>> grid,vector<vector<long long>> &dp)\n {\n // if(i==m-1 && j==n-1)\n // return grid[i][j];\n\n // if(i==m || j==n)\n // return INT_MAX;\n\n // if(dp[i][j]!=-1)\n // ret... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n for(int i = 0;i<n;i++){\n for(int j = 0;j<m;j++){\n if( i == 0 && j == 0) continue;\n else if(i == 0) grid[i][j] += g... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "// class Solution {\n// public:\n// int minPathSum(vector<vector<int>>& a) {\n// int n = a.size(), m = a[0].size();\n// vector<vector<int>>dp(n, vector<int>(m)); \n// dp[0][0] = a[0][0];\n// for(int i = 1;i < n;i++){\n// dp[i][0] = (a[i][0] + dp[i-1][0]);\n//... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int safeGet(vector<vector<int>>& grid, int i, int j) {\n if(i>=0 && j>=0 && i<grid.size() && j<grid[0].size()) return grid[i][j];\n return ((i==0 && j<0) || (j==0 && i<0))? 0 : INT_MAX;\n }\n int minPathSum(vector<vector<int>>& grid) {\n int M = gri... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int n=grid.size(),m=grid[0].size();\n // last row\n for(int j=m-2;j>=0;j--)\n grid[n-1][j]+=grid[n-1][j+1];\n // last col\n for(int i=n-2;i>=0;i--)\n grid[i][m-1]+=grid[i+1][m-1];\n for(int i=n-2;i>... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n const int m = grid.size();\n const int n = grid[0].size();\n\n for(int i = 0; i < m ; i++)\n for(int j = 0 ; j < n ; ++j)\n if(i > 0 && j > 0)\n grid[i][j] += min(grid[i - 1... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n const int m = grid.size();\n const int n = grid[0].size();\n\n for (int i = 0; i < m; ++i)\n for (int j =0; j < n; ++j)\n if (i > 0 && j > 0)\n grid[i][j] +=min(grid[i-1][j],grid[i][j-1]);\n\n... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int getSmallestNeighbor(vector<vector<int>> & grid, int y, int x) {\n if (y - 1 < 0 && x - 1 < 0)\n return 0;\n else if (y - 1 < 0)\n return grid[y][x-1];\n else if (x - 1 < 0) {\n return grid[y-1][x];\n }\n\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\n public:\n int minPathSum(vector<vector<int>>& grid) {\n const int m = grid.size();\n const int n = grid[0].size();\n\n for (int i = 0; i < m; ++i)\n for (int j = 0; j < n; ++j)\n if (i > 0 && j > 0)\n grid[i][j] += min(grid[i - 1][j], grid[i][j - 1]);\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int n = grid.size(), m = grid[0].size();\n int dp[n + 1][m + 1];\n for (int i = 0; i < n + 1; i++){\n for (int j = 0; j <= m; j++){\n dp[i][j] = 900000;\n }\n }\n ... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n int f[m][n];\n f[0][0] = grid[0][0];\n for (int i = 1; i < m; ++i) {\n f[i][0] = f[i - 1][0] + grid[i][0];\n }\n for (int j = 1; j < n... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int ispossible(int i,int j,int m, int n){\n if(i>=0&&i<m&&j>=0&&j<n) return 1;\n return 0;\n }\n \n int minPathSum(vector<vector<int>>& grid) {\n\n int m=grid.size();\n int n=grid[0].size();\n\n int dp[m][n];\n\n for(int i=0;... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m = grid.size(), n = grid[0].size();\n int f[m][n];\n f[0][0] = grid[0][0];\n for (int i = 1; i < m; ++i) {\n f[i][0] = f[i - 1][0] + grid[i][0];\n }\n for (int j = 1; j < n... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "\nclass Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m=grid.size();\n int n=grid[0].size();\n int dp[m+1][n+1];\n for(int i=0;i<=n;i++)\n {\n dp[0][i]=0;\n }\n for(int i=0;i<=m;i++)\n {\n dp[i][0]=0;... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int dyn(vector<vector<int>>& grid, vector<vector<int>>& dp, int n, int m)\n {\n if(n==0 && m==0)\n return grid[0][0];\n\n if(n<0 || m<0)\n return 10000000;\n \n if(dp[n][m]!=-1)\n return dp[n][m];\n \n return d... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int dyn(vector<vector<int>>& grid, vector<vector<int>>& dp, int n, int m)\n {\n if(n==0 && m==0)\n return grid[0][0];\n\n if(n<0 || m<0)\n return 1000000;\n \n if(dp[n][m]!=-1)\n return dp[n][m];\n\n return dp[n][m]=m... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\nint n,m;\nint solve(int start,int end,vector<vector<int>>&grid,vector<vector<int>>&dp)\n{\n if(start==n && end==m)\n return grid[start][end];\n if(start>n || end>m)\n return INT_MAX;\n if(dp[start][end]!=-1)\n return dp[start][end];\n int down=solve(start+1,e... |
64 | <p>Given a <code>m x n</code> <code>grid</code> filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.</p>
<p><strong>Note:</strong> You can only move either down or right at any point in time.</p>
<p> </p>
<p><strong class="example">Ex... | 3 | {
"code": "class Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n int m=grid.size();\n int n=grid[0].size();\n vector<vector<int>>dp(grid.size(),vector<int>(grid[0].size()));\n dp[0][0]=grid[0][0];\n for(int i=0;i<m;i++)\n {\n for(int j=0;j<n;... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\n bool exp(string_view s, int i) {\n if (s.length() == i + 1)\n return false;\n\n if (s[i] == '+' or s[i] == '-')\n i++;\n\n if (s.length() == i + 1)\n return false;\n\n for (; i + 1 < s.length(); i++) {\n if (s[i] ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\n constexpr inline bool exp(string_view s, int i) {\n if (s.length() == i + 1)\n return false;\n\n if (s[i] == '+' or s[i] == '-')\n i++;\n\n if (s.length() == i + 1)\n return false;\n\n for (; i + 1 < s.length(); i++) {\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\n bool exp(string_view s, int i) {\n if (s.length() == i + 1)\n return false;\n\n if (s[i] == '+' or s[i] == '-')\n i++;\n\n if (s.length() == i + 1)\n return false;\n\n for (; i + 1 < s.length(); i++) {\n if (s[i]... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\n bool exp(string_view s, int i) {\n if (s.length() == i + 1)\n return false;\n\n if (s[i] == '+' or s[i] == '-')\n i++;\n\n if (s.length() == i + 1)\n return false;\n\n for (; i + 1 < s.length(); i++) {\n if (s[i]... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "#include <string>\n#include <cctype>\n#include <cstdlib>\n\nclass Solution {\npublic:\n bool isNumber(const std::string& s) {\n int i = 0, n = s.length();\n \n // Skip leading whitespaces\n while (i < n && std::isspace(s[i])) ++i;\n \n // Check for empty string ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\npublic:\nbool isNumber(const std::string& s) {\n int n = s.length();\n if (n == 0) return false;\n\n enum State {\n START,\n SIGN,\n INTEGER,\n DOT,\n FRACTION,\n EXPONENT,\n EXPONENT_SIGN,\n EXPONENT_INTEGER\n };\n\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\npublic:\nbool isNumber(const std::string& s) {\n int n = s.length();\n if (n == 0) return false;\n\n enum State {\n START,\n SIGN,\n INTEGER,\n DOT,\n FRACTION,\n EXPONENT,\n EXPONENT_SIGN,\n EXPONENT_INTEGER\n };\n\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\npublic:\n bool isNumber(const string& s) {\n int i = 0;\n int n = s.size();\n while (i < n && isspace(s[i])) i++;\n\n if (i < n && (s[i] == '+' || s[i] == '-')) i++;\n\n bool isNumeric = false; \n while (i < n && isdigit(s[i])) {\n i++;\n isNumeric = tru... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n bool seenDigit = false;\n bool seenDigitAfterExp = true;\n bool seenDot = false;\n bool seenExp = false;\n \n for (int i = 0; i < s.size(); i++) {\n char c = s[i];\n \n if (... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\n public:\n bool isNumber(string s) {\n trim(s);\n if (s.empty())\n return false;\n\n bool seenNum = false;\n bool seenDot = false;\n bool seenE = false;\n\n for (int i = 0; i < s.length(); ++i) {\n switch (s[i]) {\n case '.':\n if (seenDot || s... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n int i = 0;\n int n = s.size();\n\n // 1. Skip leading whitespaces\n while (i < n && isspace(s[i])) i++;\n \n // 2. Handle optional sign (+/-)\n if (i < n && (s[i] == '+' || s[i] == '-')) i++;\n\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\npublic:\n\n enum {\n init,\n sign,\n integer,\n dot,\n nakeddot,\n decimal,\n exponent,\n power,\n invalid,\n };\n\n bool isNumber(string s) {\n int state = init;\n int i = 0;\n while (i < s.size(... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\nprivate:\n // This function checks if the rest of the string after 'e' is a valid integer\n bool restValidNumCheck(string &s, int ind) {\n // Skip sign if present\n if (ind < s.length()) {\n if (s[ind] == '-' || s[ind] == '+') ind++;\n }\n\n bo... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 0 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n enum State {\n START,\n SIGN,\n DIGIT,\n DOT,\n DIGIT_AFTER_DOT,\n E,\n SIGN_AFTER_E,\n DIGIT_AFTER_E,\n INVALID\n };\n\n State ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 2 | {
"code": "\nclass Solution {\npublic:\n bool isNumber(string s) {\n bool seenDigit = false;\n bool seenExponent = false;\n bool seenDot = false;\n\n for (int i = 0; i < s.length(); ++i) {\n char c = s[i];\n\n if (isdigit(c)) {\n seenDigit = true;\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 2 | {
"code": "enum STATE {\n INIT, I1, I2, I3, I4, I5, S1, S2, S3\n};\n\nbool isNum(char ch) {\n return ch >= 48 && ch <= 57;\n}\n\nclass Solution {\npublic:\n bool isTrueState(STATE s) {\n return s == S1 || s == S2 || s == S3;\n }\n\n bool isNumber(string s) {\n STATE curr = INIT;\n\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n if (s.empty()) {\n return false;\n }\n\n // An exponent is defined with an exponent notation 'e' or 'E' followed by an integer number.\n auto is_exponent = [&](int idx) {\n \n if (s[idx] ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n int index=0;\n bool leading_dig=false, after_dot_dig=false;\n\n auto skip_digits = [&s, &index](){\n int before = index;\n while (index<s.size() && s[index]>47 && s[index]<58)\n index++;\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n //explanation and comments in previous submission\n bool valid_integer(string s, int i){\n int n = s.size();\n if(i >= n)\n return false;\n int number_seen = false;\n if(s[i] == '-' || s[i] == '+')\n i++;\n while(i <... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n int index=0;\n bool leading_dig=false, after_dot_dig=false;\n\n auto skip_digits = [&s, &index](){\n int before = index;\n while (index<s.size() && s[index]>47 && s[index]<58)\n index++;\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n if (s.empty()) {\n return false;\n }\n\n // An exponent is defined with an exponent notation 'e' or 'E' followed by an integer number.\n auto is_exponent = [&](int idx) {\n \n if (s[idx] ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\nprivate:\n string s;\n\n bool isInteger(int& idx_) {\n int idx = idx_;\n char c = s[idx];\n\n if (c == '+' || c == '-')\n c = s[++idx];\n \n int start = idx;\n\n while (c >= '0' && c <= '9')\n c = s[++idx];\n\n i... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isInt(string s){\n if(s.size() == 1){\n return (s[0] <= '9' && s[0] >= '0');\n }\n if(!(s[0] == '-' || s[0] == '+' || s[0] <= '9' && s[0] >= '0')){\n return false;\n }\n for(int i = 1; i<s.size(); i++){\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n// use trim the string without beginning blank and ending blank\n bool isNumber(string s) {\n s = trim(s);\n\n bool hasDot = false, hasE = false, Ne= false, eN = false;\n for(int i =0; i<s.size(); i++) {\n char c = s[i];\n if(c >= '0'... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n int idx = 0;\n while (idx < s.size()) {\n if (s[idx] == 'E' || s[idx] == 'e') {\n break;\n }\n idx++;\n }\n if (idx == s.size()) {\n return isPureNumber(s, 1); /... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n #define sz(s) (int)s.size()\n bool isInteger(string s)\n {\n if(s.size()==0)\n {\n return 0;\n }\n if(s[0]=='+'||s[0]=='-')\n {\n s=s.substr(1,sz(s)-1);\n if(sz(s)==0)return 0;\n }\n for(i... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isDecimal(string& s){\n size_t start = 0;\n if(s[start] == '+' || s[start] == '-'){\n ++start;\n }\n size_t posOfDot = s.find('.');\n if(posOfDot == string::npos){\n return isInteger(s);\n }\n string ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isDecimal(string& s){\n size_t start = 0;\n if(s[start] == '+' || s[start] == '-'){\n ++start;\n }\n size_t posOfDot = s.find('.');\n if(posOfDot == string::npos){\n return isInteger(s);\n }\n string ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\nbool c(string s){\n for(auto i:s){\n if(i>='a'&& i<='z' && i!='e'|| i>='A'&& i<='Z' && i!='E'){\n return 0;\n }\n i++;\n }\n return 1;\n}\nbool cbp(string s,int n){\n int i=0;\n while(i<n){\n if(s[i]=='e' || s[i]=='E' || s... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "// Time: O(n)\n// Space: O(1)\n\n// automata: http://images.cnitblog.com/i/627993/201405/012016243309923.png\nclass Solution {\npublic:\n bool isNumber(string s) {\n enum InputType {\n INVALID, // 0\n SPACE, // 1\n SIGN, // 2\n DIGIT, ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n int i = 0;\n while (i < s.size()) {\n if (s[i] == 'E' || s[i] == 'e') {\n return (isInterger(s.substr(0, i)) || isDecimal(s.substr(0, i))) && \n isInterger(s.substr(i+1, string::npos));\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n\n bool check(string str,int flag){\n int i=0,cnt=0,check=0,num=0;\n\n while(i<str.size()){\n if(str[i]=='.'){\n if(flag==1)\n return false;\n else if(cnt>0)\n return false;\n\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool IsDigits(const std::string& s) {\n if (s.empty()) {\n return false;\n }\n for (char ch : s) {\n if (ch < '0' || ch > '9') {\n return false;\n }\n }\n return true;\n }\n bool IsIntege... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isDigit(char a){\n return a >= '0' && a <= '9';\n }\n bool isSign(char a){\n return a=='+' || a=='-';\n }\n bool validateNumber(string &num){\n if(num.size()==1 && !isDigit(num[0])) return false;\n int i = isSign(num[0]);\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isInteger(string s){\n auto dotCt=count(s.begin(),s.end(), '.');\n if(dotCt>0) return false;\n int start=0;\n if(s[0]=='+' || s[0]=='-') start++;\n if(s==\"+\" || s==\"-\") return false;\n \n for(int i=start; i<s.size(); i... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\nbool isIntDec(string s, bool integer = true) {\nif(s.length() && (s[0]=='+'||s[0]=='-')) s = s.substr(1); // begins with sign; skip that\nreturn s.length()>0 && // empty not OK\ns.find_first_not_of(integer ? \"0123456789\" : \".0123456789\") == string::npos // contains only numbers and op... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n\n auto isExponent = [](char c ){ return c == 'e' || c == 'E'; };\n\n auto eIter = std::find_if(s.begin(), s.end(), isExponent);\n\n if ( eIter != s.end() ){\n\n string exp = s.substr(eIter - s.begin() + 1);\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n /*\n 1. Check whitespace\n 2. Check Sign characters\n 3. Check if its expoential \n - Check presence of 'e' or 'E'\n - Check presence of dot '.'\n 4. Check if there is any digit\n 5. check if we have any char other than 'e... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "static const regex number_regex(\"[+-]?((\\\\d+)|((\\\\d+\\\\.)|(\\\\d+\\\\.\\\\d+)|(\\\\.\\\\d+)))([eE][+-]?\\\\d+)?\");\n\nclass Solution {\npublic:\n bool isNumber(string s) {\n #if 0\n return regex_match(s,number_regex);\n #endif\n #if 1 \n if(s.size()==0) return false;\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n unordered_map<char, int> mp;\n mp['+'] = 0;\n mp['-'] = 0;\n mp['e'] = 0;\n mp['E'] = 0;\n mp['.'] = 0;\n bool has_digit = false;\n bool has_exponent = false;\n\n for (int i = 0; i < s.... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isNumber(string s) {\n // @akshay\n return isint2(s) || isdecimal(s) || isexp(s);\n }\n\n bool isint(string s){\n bool sign = false;\n if(s.size() > 0){\n if(!(isdigit(s[0]) || s[0] == '-' || s[0] == '+')) return false;\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n\n int indexOf( char ch, string & s) {\n for( int i=0; i<s.length(); i++) {\n if(s[i]==ch) {\n return i;\n }\n }\n return -1;\n }\n\n bool parsePositiveWholeNumber( string s) {\n if(s.empty()) {\n ... |
65 | <p>Given a string <code>s</code>, return whether <code>s</code> is a <strong>valid number</strong>.<br />
<br />
For example, all the following are valid numbers: <code>"2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7&... | 3 | {
"code": "class Solution {\npublic:\n bool isDigits(string s, int start, int end) {\n if(start > end) return false;\n for(int i = start; i <= end; i++) {\n if(s[i] >= '0' && s[i] <= '9') {\n continue;\n } else {\n return false;\n }\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.