java.lang.Object
g2201_2300.s2224_minimum_number_of_operations_to_convert_time.Solution

public class Solution extends Object
2224 - Minimum Number of Operations to Convert Time.<p>Easy</p> <p>You are given two strings <code>current</code> and <code>correct</code> representing two <strong>24-hour times</strong>.</p> <p>24-hour times are formatted as <code>&quot;HH:MM&quot;</code>, where <code>HH</code> is between <code>00</code> and <code>23</code>, and <code>MM</code> is between <code>00</code> and <code>59</code>. The earliest 24-hour time is <code>00:00</code>, and the latest is <code>23:59</code>.</p> <p>In one operation you can increase the time <code>current</code> by <code>1</code>, <code>5</code>, <code>15</code>, or <code>60</code> minutes. You can perform this operation <strong>any</strong> number of times.</p> <p>Return <em>the <strong>minimum number of operations</strong> needed to convert</em> <code>current</code> <em>to</em> <code>correct</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> current = &ldquo;02:30&rdquo;, correct = &ldquo;04:35&rdquo;</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong></p> <p>We can convert current to correct in 3 operations as follows:</p> <ul> <li> <p>Add 60 minutes to current. current becomes &ldquo;03:30&rdquo;.</p> </li> <li> <p>Add 60 minutes to current. current becomes &ldquo;04:30&rdquo;.</p> </li> <li> <p>Add 5 minutes to current. current becomes &ldquo;04:35&rdquo;.</p> </li> </ul> <p>It can be proven that it is not possible to convert current to correct in fewer than 3 operations.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> current = &ldquo;11:00&rdquo;, correct = &ldquo;11:01&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> We only have to add one minute to current, so the minimum number of operations needed is 1.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>current</code> and <code>correct</code> are in the format <code>&quot;HH:MM&quot;</code></li> <li><code>current <= correct</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • convertTime

      public int convertTime(String current, String correct)