I have been trying to convert following code to Python but I couldn't figure out the way to do it. How can I slice a boolean list in Python?
I couldn't find how to create boolean list with same length of the input. I kept getting error at the line: checks[j] = true when I try to convert it to Python. I guess slicing a boolean list is not allowed in Python.
int result = 0;
Boolean lightsOn = true;
Boolean[] checks = new Boolean[input.Length];
for (int i = 0; i < input.Length; i++)
{
int j = input[i] - 1;
checks[j] = true;
for (; 0 <= j; j--)
{
if (!checks[j]) # also this part
{
lightsOn = false;
break;
}
}
if (lightsOn)
{
result++;
}
lightsOn = true;
}
return result;
from Recent Questions - Stack Overflow https://ift.tt/3lbmg8j
https://ift.tt/eA8V8J
Comments
Post a Comment