My solution does not work with this array [0,3,7,2,5,8,4,6,0,1]
class Solution {
public:
int longestConsecutive(vector<int>& nums) {
sort(nums.begin(), nums.end());
int length = 0;
for(int i = 0; i < nums.size() - 2; i++)
{
if(nums[i] - nums[i + 1] == -1)
{
length++;
}
}
return length + 1;
}
};
I tried plugging it even to chatgpt, but it does not spot the problem.
1
WtnffwtwwtwtwthrwtwhtwfwtfjtjththwhthtwthrtejwtjtutwtewrbwrwrbwtbgsacnsgnsgjsgjafnafbgsfbaaaxhstdbaybdaubdsufnsufnsufsnufsnfhnfsundaubdufnsusfdunfwusbsfjsgnfnfabafbfafBffanfanffjsnsfnfsnfanfajfahrharjrahfahrhhdhdvdabfabfahfafahtafagjgsfangjfsgjfhtuhtgsstgsghhssgeyjdxnbndhfhyrkurukjfkhdhkhh
ravi meshram is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.