Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code for count-negative-numbers-in-a-sorted-matrix #74

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
17 changes: 17 additions & 0 deletions C++/1351.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
int countNegatives(vector<vector<int>>& grid) {
int row=grid.size();
int col=grid[0].size();
int ans=0;
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
if(grid[i][j]<0)
ans++;
}
}
return ans;
}
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Or from the Sheet 1 of this [Google Sheet](https://bit.ly/2EUhwnw)
| 0983 | [Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets/) | Here dp(i) is the cost to travel from day days[i] to the end of the plan. if days[j] < days[i] + 1 then j1=j. if days[j] < days[i] + 7 then j=j7. if days[j] < days[i] + 30 then j=j30 . dp(i)=min(dp(j1)+costs[0],dp(j7)+costs[1],dp(j30)+costs[2]) | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0983.java) | O(n) | O(n) | Medium | Dynamic Programming | [📺](https://www.youtube.com/watch?v=2AnrAlCA578) |
| 1347 | [Minimum Number of Steps to Make Two Strings Anagram](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram/) | Add 1 for char in s and remove 1 for char in t | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/1347.java) [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/1347.py) | O(n+m) | O(1) | Medium | Hash Table Heap | [📺](https://www.youtube.com/watch?v=xXXOpOYWtRE) |
| 1352 | [Product of the Last K Numbers](https://leetcode.com/problems/product-of-the-last-k-numbers/) | Add new element to list by multiplying it with previous number and return arr[n-1]/arr[n-k-1] | [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/1352.py) | O(1) | O(1) | Medium | Array Design | [📺](https://www.youtube.com/watch?v=8CuVduv0Kyg) |

| 1351 | [Count negative numbers in a sorted matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/) |Find number of rows and columns, initialise a counter by zero, then traverse through them using two for loops and increse the counter if a negative number is encountered | [C++ ](https://github.com/beertocode/LeetCode-Solutions-1/blob/mybranch1/C%2B%2B/1351.cpp) | O(m*n) | O(1) | Easy | Array traversal | [📺](https://www.youtube.com/results?search_query=count+negative+numbers+in+a+sorted+matrix+leetcode) |

Format
| 0000 | [Ques name]() | Algo | [Java]() | O() | O() | Easy | Category | [📺]() |
Expand Down