LeetCode-3 无重复字符的最长子串

  • C++ 
class Solution {
public:
	int lengthOfLongestSubstring(string s) {
		int num = s.length();
		int result = 0;
		int begin = 0;
		for (int end = 0; end < num; end++) {
			for (int index = begin; index < end; index++) {
				if (s[end] == s[index]) {
					begin = index + 1;
					break;
				}
			}
			if (result < end - begin + 1) {
				result = end - begin + 1;
			}
		}
		return result;
	}
};

猜你喜欢

转载自blog.csdn.net/lolimostlovely/article/details/82932827