/**
* Definition for a street.
* class Street {
* public Street(int[] doors);
* public void openDoor();
* public void closeDoor();
* public boolean isDoorOpen();
* public void moveRight();
* public void moveLeft();
* }
*/
class Solution {
public int houseCount(Street street, int k) {
for (int i = 0; i < k; i++) {
street.closeDoor();
street.moveRight();
}
int ans = 1;
street.openDoor();
street.moveRight();
while (!street.isDoorOpen()) {
ans++;
street.moveRight();
}
return ans;
}
}
# Definition for a street.
# class Street:
# def openDoor(self):
# pass
# def closeDoor(self):
# pass
# def isDoorOpen(self):
# pass
# def moveRight(self):
# pass
# def moveLeft(self):
# pass
class Solution:
def houseCount(self, street: Optional['Street'], k: int) -> int:
while (k):
street.closeDoor()
street.moveRight()
k -= 1
street.openDoor()
street.moveRight()
ans = 1
while not street.isDoorOpen():
ans += 1
street.moveRight()
return ans
def houseCount2(self, street: Optional['Street'], k: int) -> int:
la, x = 0, k
if not street.isDoorOpen():
street.openDoor()
while k:
k -= 1
street.moveRight()
if street.isDoorOpen():
street.closeDoor()
la = 0
else:
la += 1
return x - la