java.lang.Object
g2401_2500.s2437_number_of_valid_clock_times.Solution

public class Solution extends Object
2437 - Number of Valid Clock Times.<p>Easy</p> <p>You are given a string of length <code>5</code> called <code>time</code>, representing the current time on a digital clock in the format <code>&quot;hh:mm&quot;</code>. The <strong>earliest</strong> possible time is <code>&quot;00:00&quot;</code> and the <strong>latest</strong> possible time is <code>&quot;23:59&quot;</code>.</p> <p>In the string <code>time</code>, the digits represented by the <code>?</code> symbol are <strong>unknown</strong> , and must be <strong>replaced</strong> with a digit from <code>0</code> to <code>9</code>.</p> <p>Return <em>an integer</em> <code>answer</code><em>, the number of valid clock times that can be created by replacing every</em> <code>?</code><em>with a digit from</em> <code>0</code> <em>to</em> <code>9</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> time = &ldquo;?5:00&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> We can replace the ? with either a 0 or 1, producing &ldquo;05:00&rdquo; or &ldquo;15:00&rdquo;. Note that we cannot replace it with a 2, since the time &ldquo;25:00&rdquo; is invalid. In total, we have two choices.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> time = &ldquo;0?:0?&rdquo;</p> <p><strong>Output:</strong> 100</p> <p><strong>Explanation:</strong> Each ? can be replaced by any digit from 0 to 9, so we have 100 total choices.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> time = &ldquo;??:??&rdquo;</p> <p><strong>Output:</strong> 1440</p> <p><strong>Explanation:</strong> There are 24 possible choices for the hours, and 60 possible choices for the minutes. In total, we have 24 * 60 = 1440 choices.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>time</code> is a valid string of length <code>5</code> in the format <code>&quot;hh:mm&quot;</code>.</li> <li><code>&quot;00&quot; <= hh <= &quot;23&quot;</code></li> <li><code>&quot;00&quot; <= mm <= &quot;59&quot;</code></li> <li>Some of the digits might be replaced with <code>'?'</code> and need to be replaced with digits from <code>0</code> to <code>9</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countTime

      public int countTime(String time)