Download benchmarks/Algorithms/majority_element/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 282 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/majority_element/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/majority_element/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/majority_element/solution.c
282 Bytes
| int majorityElement(int* nums, int numsSize) | |
| { | |
| int vote = 0; | |
| int candidate = 0; | |
| for (int i = 0; i < numsSize; i++) { | |
| if (vote == 0) { | |
| candidate = nums[i]; | |
| } | |
| vote += (nums[i] == candidate) ? 1 : -1; | |
| } | |
| return candidate; | |
| } | |