/**
* Definition for a street.
* class Street {
* public:
* Street(vector<int> doors);
* void closeDoor();
* bool isDoorOpen();
* void moveRight();
* };
*/
class Solution {
public:
int houseCount(Street *s, int k) {
while (!s->isDoorOpen())
s->moveRight();
int ans;
for (int i = 1; i <= k; i++) {
s->moveRight();
if (s->isDoorOpen()) {
ans = i;
s->closeDoor();
}
}
return ans;
}
};
/**
* Definition for a street.
* class Street {
* public Street(int[] doors);
* public void closeDoor();
* public boolean isDoorOpen();
* public void moveRight();
* }
*/
class Solution {
public int houseCount(Street s, int k) {
while (!s.isDoorOpen())
s.moveRight();
int ans = 0;
for (int i = 1; i <= k; i++) {
s.moveRight();
if (s.isDoorOpen()) {
ans = i;
s.closeDoor();
}
}
return ans;
}
}
/**
* Definition for a street.
* type Street interface {
* CloseDoor()
* IsDoorOpen() bool
* MoveRight()
* }
*/
func houseCount(s Street, k int) (ans int) {
for !s.IsDoorOpen() {
s.MoveRight()
}
for i := 1; i <= k; i++ {
s.MoveRight()
if s.IsDoorOpen() {
ans = i
s.CloseDoor()
}
}
return
}
# Definition for a street.
# class Street:
# def closeDoor(self):
# pass
# def isDoorOpen(self):
# pass
# def moveRight(self):
# pass
class Solution:
def houseCount(self, s: Optional['Street'], k: int) -> int:
while not s.isDoorOpen():
s.moveRight()
for i in range(1, k + 1):
s.moveRight()
if s.isDoorOpen():
ans = i
s.closeDoor()
return ans