Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 613 Bytes

File metadata and controls

28 lines (23 loc) · 613 Bytes

LeetCode Records - Question 2728 Count Houses in a Circular Street

Attempt 1: Close all the doors first

class Solution {
    public int houseCount(Street street, int k) {
        for (int i = 0; i < k; i++) {
            street.closeDoor();
            street.moveRight();
        }

        for (int i = 0; i < k; i++) {
            if (street.isDoorOpen()) {
                return i;
            }

            street.openDoor();
            street.moveRight();
        }

        return k;
    }
}
  • Runtime: 2 ms (Beats: 78.95%)
  • Memory: 44.29 MB (Beats: 68.42%)