Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- serverless
- CHECK
- cloudwatch
- SageMaker
- terraform
- IaC
- Lamda
- kubernetes
- sns
- 분산시스템
- amazonqcli
- rds
- lambda
- Validation
- PACELC
- 병목
- CAP
- fcm
- aws
Archives
- Today
- Total
잡다한 IT 지식
(아직안끝남)1351. Count Negative Numbers in a Sorted Matrix 본문
이중 배열에서 0보다 작은 수들의 갯수를 구하면 됩니다.
문제에서 내림차순으로 숫자가 감소하기 때문에 처음 -가 나오면 나머지는 전부 -입니다.
class Solution {
public int countNegatives(int[][] grid) {
int answer = 0;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[i].length; j++) {
if (grid[i][j] < 0) {
answer += grid[i].length - j;
}
}
}
return answer;
}
}
해설 중에 이진탐색 사용한 거 있어서 그거 한번 짜보기로함.
'알고리즘 문제 풀이' 카테고리의 다른 글
1431. Kids With the Greatest Number of Candies (0) | 2021.06.10 |
---|---|
1827. Minimum Operations to Make the Array Increasing (0) | 2021.06.08 |
1528. Shuffle String (0) | 2021.05.25 |
1281. Subtract the Product and Sum of Digits of an Integer (0) | 2021.05.25 |
1561. Maximum Number of Coins You Can Get (0) | 2021.05.13 |