Download code/validation/C++/0032786_003LongestString.cpp from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 884 Bytes
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/C%2B%2B/0032786_003LongestString.cpp
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/code/validation/C++/0032786_003LongestString.cpp
-
curl -L -o 0032786_003LongestString.cpp https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/C%2B%2B/0032786_003LongestString.cpp
884 Bytes
| // | |
| // Created by yaning on 17-6-1. | |
| // | |
| using namespace std; | |
| class Solution { | |
| public: | |
| int lengthOfLongestSubstring(string s) { | |
| int left = 0; | |
| int right = 0; | |
| int maxLength = 0; | |
| int length = 0; | |
| int check[255] = { 0, }; | |
| for (; right < s.length(); right++) { | |
| if (check[s[right]] == 1) { | |
| for (; s[left] != s[right]; left++) { | |
| check[s[left]] = 0; | |
| length--; | |
| } | |
| left++; | |
| } else { | |
| check[s[right]] = 1; | |
| length++; | |
| if (length > maxLength) { | |
| maxLength = length; | |
| } | |
| } | |
| } | |
| return maxLength; | |
| } | |
| }; | |
| int main() { | |
| Solution sol; | |
| cout << sol.lengthOfLongestSubstring("12342543921"); | |
| return 0; | |
| } | |