Class Solution
java.lang.Object
g1501_1600.s1553_minimum_number_of_days_to_eat_n_oranges.Solution
1553 - Minimum Number of Days to Eat N Oranges.<p>Hard</p>
<p>There are <code>n</code> oranges in the kitchen and you decided to eat some of these oranges every day as follows:</p>
<ul>
<li>Eat one orange.</li>
<li>If the number of remaining oranges <code>n</code> is divisible by <code>2</code> then you can eat <code>n / 2</code> oranges.</li>
<li>If the number of remaining oranges <code>n</code> is divisible by <code>3</code> then you can eat <code>2 * (n / 3)</code> oranges.</li>
</ul>
<p>You can only choose one of the actions per day.</p>
<p>Given the integer <code>n</code>, return <em>the minimum number of days to eat</em> <code>n</code> <em>oranges</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 10</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> You have 10 oranges.</p>
<p>Day 1: Eat 1 orange, 10 - 1 = 9.</p>
<p>Day 2: Eat 6 oranges, 9 - 2*(9/3) = 9 - 6 = 3. (Since 9 is divisible by 3)</p>
<p>Day 3: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1.</p>
<p>Day 4: Eat the last orange 1 - 1 = 0.</p>
<p>You need at least 4 days to eat the 10 oranges.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 6</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> You have 6 oranges.</p>
<p>Day 1: Eat 3 oranges, 6 - 6/2 = 6 - 3 = 3. (Since 6 is divisible by 2).</p>
<p>Day 2: Eat 2 oranges, 3 - 2*(3/3) = 3 - 2 = 1. (Since 3 is divisible by 3)</p>
<p>Day 3: Eat the last orange 1 - 1 = 0.</p>
<p>You need at least 3 days to eat the 6 oranges.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 2 * 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minDays
public int minDays(int n)
-