Download benchmarks/Algorithms/longest_nondecreasing_subsequence/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 527 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/longest_nondecreasing_subsequence/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/longest_nondecreasing_subsequence/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/longest_nondecreasing_subsequence/solution.c
527 Bytes
| int lengthOfLNDS(int *nums, int numsSize) | |
| { | |
| int tails[100000]; | |
| for (int fill = 0; fill < numsSize; ++fill) { | |
| tails[fill] = 0; | |
| } | |
| int len = 0; | |
| for (int i = 0; i < numsSize; ++i) { | |
| int x = nums[i]; | |
| int left = 0; | |
| int right = len; | |
| while (left < right) { | |
| int mid = left + (right - left) / 2; | |
| if (tails[mid] <= x) { | |
| left = mid + 1; | |
| } else { | |
| right = mid; | |
| } | |
| } | |
| tails[left] = x; | |
| if (left == len) { | |
| len = len + 1; | |
| } | |
| } | |
| return len; | |
| } | |