leetcode 的问题在vs里运行正确,但是在leetcode里就有错误
题目 :给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。
代码 :
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int Cycle = 0, Character_start = 0, Character_end = 1, max = 1, lenght = s.size(), Character_end2 = 99;
while (Cycle < lenght) {
while (Character_start < lenght) {
if (Character_start < lenght && Character_start != Character_end2) {
while (s[Character_end] != s[Character_start] && Character_end != Character_end2 && Character_end != lenght) {
Character_end = Character_end + 1;
}
Character_end2 = Character_end;
Character_start = Character_start + 1;
Character_end = Character_start + 1;
}
else {
max < Character_end - Cycle ? max = Character_end - Cycle : max = max;
Cycle = Cycle + 1;
Character_start = Cycle;
Character_end = Cycle + 1;
Character_end2 = 99;
}
}
max < Character_end - Cycle ? max = Character_end - Cycle : max = max;
return max - 1;
}
return max - 1;
};
报错
26行的return max - 1;
后面加上一个后括号 }
或者说,你第四行缩进少了,导致你自己看着都别扭,其实少了一层后括号。
你 把缩进弄一下,就知道 你 少写了一个 右花括号
额,请检查的代码中 “{ }”的数量,不成对,少了“}” 报错提示看不懂嘛?