What is the length of the longest substring containing only 1 after setting at most one char to 1?
For example, given s="1101100111", the answer is 5
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int Largeststring(string nums) {
int left = 0, curr = 0, ans = 0;
for (int right = 0; right < nums.size(); right++) {
if (nums[right] == "0") {
curr++;
}
while (curr > 0) {
if (nums[left] == "0") {
curr--;
}
}
ans = max(ans, right - left + 1);
}
}
int main()
{
string s = "1101100111";
cout << Largeststring(s);
}
In this code it gives the compile time error
"error: ISO C++ forbids comparison between pointer and integer [-fpermissive]" for the lines "nums[right] == "0" and the similar line for nums left.
Firstly, in this case I don't understand what the pointer is and there is no integer as well, I thought it was because I was calling by reference it was giving this error, but I switched it to call by value, but the error seems to persist
So initially I tried using a char
vector, I thought the error was that because characters are initialised individually to the char
vector, but when I switched to string
the same problem seems to exist.
Kindly assist me in this problem.