Download benchmarks/Algorithms/maximum_subarray/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 317 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/maximum_subarray/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/maximum_subarray/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/maximum_subarray/solution.c
317 Bytes
| int max(int a, int b) | |
| { | |
| return (a > b) ? a : b; | |
| } | |
| int max_sub_array(int *arr, int n) | |
| { | |
| if (n == 0) { | |
| return 0; | |
| } | |
| int cur = arr[0]; | |
| int res = arr[0]; | |
| for (int i = 1; i < n; i++) { | |
| cur = max(arr[i], cur + arr[i]); | |
| res = max(res, cur); | |
| } | |
| return res; | |
| } | |