|
| 1 | +# [2753. Count Houses in a Circular Street II](https://leetcode.com/problems/count-houses-in-a-circular-street-ii) |
| 2 | + |
| 3 | +[中文文档](/solution/2700-2799/2753.Count%20Houses%20in%20a%20Circular%20Street%20II/README.md) |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +<p>You are given an object <code>street</code> of class <code>Street</code> that represents a <strong>circular</strong> street and a positive integer <code>k</code> which represents a maximum bound for the number of houses in that street (in other words, the number of houses is less than or equal to <code>k</code>). Houses' doors could be open or closed initially (at least one is open).</p> |
| 8 | + |
| 9 | +<p>Initially, you are standing in front of a door to a house on this street. Your task is to count the number of houses in the street.</p> |
| 10 | + |
| 11 | +<p>The class <code>Street</code> contains the following functions which may help you:</p> |
| 12 | + |
| 13 | +<ul> |
| 14 | + <li><code>void closeDoor()</code>: Close the door of the house you are in front of.</li> |
| 15 | + <li><code>boolean isDoorOpen()</code>: Returns <code>true</code> if the door of the current house is open and <code>false</code> otherwise.</li> |
| 16 | + <li><code>void moveRight()</code>: Move to the right house.</li> |
| 17 | +</ul> |
| 18 | + |
| 19 | +<p><strong>Note</strong> that by <strong>circular</strong> street, we mean if you number the houses from <code>1</code> to <code>n</code>, then the right house of <code>house<sub>i</sub></code> is <code>house<sub>i+1</sub></code> for <code>i < n</code>, and the right house of <code>house<sub>n</sub></code> is <code>house<sub>1</sub></code>.</p> |
| 20 | + |
| 21 | +<p>Return <code>ans</code> <em>which represents the number of houses on this street.</em></p> |
| 22 | + |
| 23 | +<p> </p> |
| 24 | +<p><strong class="example">Example 1:</strong></p> |
| 25 | + |
| 26 | +<pre> |
| 27 | +<strong>Input:</strong> street = [1,1,1,1], k = 10 |
| 28 | +<strong>Output:</strong> 4 |
| 29 | +<strong>Explanation:</strong> There are 4 houses, and all their doors are open. |
| 30 | +The number of houses is less than k, which is 10.</pre> |
| 31 | + |
| 32 | +<p><strong class="example">Example 2:</strong></p> |
| 33 | + |
| 34 | +<pre> |
| 35 | +<strong>Input:</strong> street = [1,0,1,1,0], k = 5 |
| 36 | +<strong>Output:</strong> 5 |
| 37 | +<strong>Explanation:</strong> There are 5 houses, and the doors of the 1st, 3rd, and 4th house (moving in the right direction) are open, and the rest are closed. |
| 38 | +The number of houses is equal to k, which is 5. |
| 39 | +</pre> |
| 40 | + |
| 41 | +<p> </p> |
| 42 | +<p><strong>Constraints:</strong></p> |
| 43 | + |
| 44 | +<ul> |
| 45 | + <li><code>n == number of houses</code></li> |
| 46 | + <li><code>1 <= n <= k <= 10<sup>5</sup></code></li> |
| 47 | + <li><code>street</code> is circular by definition provided in the statement.</li> |
| 48 | + <li>The input is generated such that at least one of the doors is open.</li> |
| 49 | +</ul> |
| 50 | + |
| 51 | +## Solutions |
| 52 | + |
| 53 | +<!-- tabs:start --> |
| 54 | + |
| 55 | +### **Python3** |
| 56 | + |
| 57 | +```python |
| 58 | + |
| 59 | +``` |
| 60 | + |
| 61 | +### **Java** |
| 62 | + |
| 63 | +```java |
| 64 | + |
| 65 | +``` |
| 66 | + |
| 67 | +### **C++** |
| 68 | + |
| 69 | +```cpp |
| 70 | + |
| 71 | +``` |
| 72 | + |
| 73 | +### **Go** |
| 74 | + |
| 75 | +```go |
| 76 | + |
| 77 | +``` |
| 78 | + |
| 79 | +### **...** |
| 80 | + |
| 81 | +``` |
| 82 | +
|
| 83 | +``` |
| 84 | + |
| 85 | +<!-- tabs:end --> |
0 commit comments