Download benchmarks/Algorithms/house_robber/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 299 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/house_robber/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/house_robber/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/house_robber/solution.c
299 Bytes
| int rob(int *nums, int n) | |
| { | |
| int prev2 = 0; | |
| int prev1 = 0; | |
| for (int i = 0; i < n; ++i) { | |
| int take = prev2 + nums[i]; | |
| int skip = prev1; | |
| int cur; | |
| if (take > skip) { | |
| cur = take; | |
| } else { | |
| cur = skip; | |
| } | |
| prev2 = prev1; | |
| prev1 = cur; | |
| } | |
| return prev1; | |
| } | |