50125. Consecutive 1’s with Function

難度:3/5 Used Time: 15:30

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include "findLength.h"

#define max(a,b) ((a)>(b)?(a):(b))

int is_valid(int x, int y, int n){
return x >= 0 && y >= 0 && x < n && y < n;
}

int findLength (int arr[][256], int n, int r, int c, int dr, int dc){
int now_cnt = 0;
int max_cnt = 0;
while(is_valid(r, c, n)){
if(arr[r][c] == 1) now_cnt += 1;
else now_cnt = 0;
max_cnt = max(max_cnt, now_cnt);
r += dr, c += dc;
}
return max_cnt;
}


50125. Consecutive 1’s with Function
https://aaronlin1229.github.io/judgegirl_50125/
Author
Akizumi
Posted on
July 17, 2023
Licensed under